Package test_suite :: Package system_tests :: Module relax_disp
[hide private]
[frames] | no frames]

Source Code for Module test_suite.system_tests.relax_disp

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2006-2015 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2009 Sebastien Morin                                          # 
   5  # Copyright (C) 2013-2014 Troels E. Linnet                                    # 
   6  #                                                                             # 
   7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   8  #                                                                             # 
   9  # This program is free software: you can redistribute it and/or modify        # 
  10  # it under the terms of the GNU General Public License as published by        # 
  11  # the Free Software Foundation, either version 3 of the License, or           # 
  12  # (at your option) any later version.                                         # 
  13  #                                                                             # 
  14  # This program is distributed in the hope that it will be useful,             # 
  15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  17  # GNU General Public License for more details.                                # 
  18  #                                                                             # 
  19  # You should have received a copy of the GNU General Public License           # 
  20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  21  #                                                                             # 
  22  ############################################################################### 
  23   
  24  # Python module imports. 
  25  from os import F_OK, access, getcwd, path, sep 
  26  import copy 
  27  from numpy import array, asarray, average, exp, median, inf, linspace, log, std, sum, zeros 
  28  from minfx.generic import generic_minimise 
  29  from random import gauss 
  30  import re, math 
  31  from tempfile import mkdtemp, NamedTemporaryFile 
  32   
  33   
  34  # relax module imports. 
  35  from auto_analyses import relax_disp 
  36  from auto_analyses.relax_disp_repeat_cpmg import DIC_KEY_FORMAT, Relax_disp_rep 
  37  from data_store import Relax_data_store; ds = Relax_data_store() 
  38  import dep_check 
  39  from lib.dispersion.variables import EXP_TYPE_CPMG_DQ, EXP_TYPE_CPMG_MQ, EXP_TYPE_CPMG_PROTON_MQ, EXP_TYPE_CPMG_PROTON_SQ, EXP_TYPE_CPMG_SQ, EXP_TYPE_CPMG_ZQ, EXP_TYPE_LIST, EXP_TYPE_R1RHO, MODEL_B14_FULL, MODEL_CR72, MODEL_CR72_FULL, MODEL_DPL94, MODEL_IT99, MODEL_LIST_FULL, MODEL_LM63, MODEL_M61B, MODEL_MP05, MODEL_NOREX, MODEL_NS_CPMG_2SITE_3D_FULL, MODEL_NS_CPMG_2SITE_EXPANDED, MODEL_NS_CPMG_2SITE_STAR_FULL, MODEL_NS_R1RHO_2SITE, MODEL_PARAMS, MODEL_R2EFF, MODEL_TP02, MODEL_TAP03 
  40  from lib.errors import RelaxError 
  41  from lib.io import extract_data, get_file_path 
  42  from lib.spectrum.nmrpipe import show_apod_extract, show_apod_rmsd, show_apod_rmsd_dir_to_files, show_apod_rmsd_to_file 
  43  from pipe_control.mol_res_spin import generate_spin_string, return_spin, spin_loop 
  44  from pipe_control.minimise import assemble_scaling_matrix 
  45  from specific_analyses.relax_disp.checks import check_missing_r1 
  46  from specific_analyses.relax_disp.estimate_r2eff import estimate_r2eff 
  47  from specific_analyses.relax_disp.data import average_intensity, check_intensity_errors, generate_r20_key, get_curve_type, has_exponential_exp_type, loop_exp_frq, loop_exp_frq_offset_point, loop_time, return_grace_file_name_ini, return_param_key_from_data, spin_ids_to_containers 
  48  from specific_analyses.relax_disp.data import INTERPOLATE_DISP, INTERPOLATE_OFFSET, X_AXIS_DISP, X_AXIS_W_EFF, X_AXIS_THETA, Y_AXIS_R2_R1RHO, Y_AXIS_R2_EFF 
  49  from specific_analyses.relax_disp.model import models_info, nesting_param 
  50  from specific_analyses.relax_disp.parameters import linear_constraints 
  51  from status import Status; status = Status() 
  52  from target_functions.relax_fit_wrapper import Relax_fit_opt 
  53  from test_suite.system_tests.base_classes import SystemTestCase 
  54   
  55   
56 -class Relax_disp(SystemTestCase):
57 """Class for testing various aspects specific to relaxation dispersion curve-fitting.""" 58
59 - def __init__(self, methodName='runTest'):
60 """Skip certain tests if the C modules are non-functional. 61 62 @keyword methodName: The name of the test. 63 @type methodName: str 64 """ 65 66 # Execute the base class method. 67 super(Relax_disp, self).__init__(methodName) 68 69 # Tests to skip. 70 blacklist = [ 71 'test_m61b_data_to_m61b' 72 ] 73 if methodName in blacklist: 74 status.skipped_tests.append([methodName, None, self._skip_type]) 75 76 # Missing module. 77 if not dep_check.C_module_exp_fn: 78 # The list of tests to skip. 79 to_skip = [ 80 "test_bug_atul_srivastava", 81 "test_bug_21344_sparse_time_spinlock_acquired_r1rho_fail_relax_disp", 82 "test_bug_9999_slow_r1rho_r2eff_error_with_mc", 83 "test_estimate_r2eff_err", 84 "test_estimate_r2eff_err_auto", 85 "test_estimate_r2eff_err_methods", 86 "test_finite_value", 87 "test_exp_fit", 88 "test_m61_exp_data_to_m61", 89 "test_r1rho_kjaergaard_auto", 90 "test_r1rho_kjaergaard_auto_check_graphs", 91 "test_r1rho_kjaergaard_man", 92 "test_r1rho_kjaergaard_missing_r1", 93 "test_value_write_calc_rotating_frame_params_auto_analysis" 94 ] 95 96 # Store in the status object. 97 if methodName in to_skip: 98 status.skipped_tests.append([methodName, 'Relax curve-fitting C module', self._skip_type]) 99 100 # If not scipy.optimize.leastsq. 101 if not dep_check.scipy_module: 102 # The list of tests to skip. 103 to_skip = [ 104 "test_estimate_r2eff_err_methods" 105 ] 106 107 # Store in the status object. 108 if methodName in to_skip: 109 status.skipped_tests.append([methodName, 'scipy.optimize.leastsq module', self._skip_type]) 110 111 # If not NMRPipe showApod program in PATH. 112 if not dep_check.showApod_software: 113 # The list of tests to skip. 114 to_skip = [ 115 "test_show_apod_extract", 116 "test_show_apod_rmsd", 117 "test_show_apod_rmsd_to_file", 118 "test_show_apod_rmsd_dir_to_files" 119 ] 120 121 # Store in the status object. 122 if methodName in to_skip: 123 status.skipped_tests.append([methodName, 'NMRPipe showApod program', self._skip_type]) 124 125 # If not matplotlib module 126 if not dep_check.matplotlib_module: 127 # The list of tests to skip. 128 to_skip = [ 129 "test_repeat_cpmg" 130 ] 131 132 # Store in the status object. 133 if methodName in to_skip: 134 status.skipped_tests.append([methodName, 'matplotlib module', self._skip_type])
135 136
137 - def setUp(self):
138 """Set up for all the functional tests.""" 139 140 # Create the data pipe. 141 self.interpreter.pipe.create('relax_disp', 'relax_disp') 142 143 # Create a temporary directory for dumping files. 144 ds.tmpdir = mkdtemp() 145 self.tmpdir = ds.tmpdir
146 147
148 - def setup_bug_22146_unpacking_r2a_r2b_cluster(self, folder=None, model_analyse=None, places = 7):
149 """Setup data for the catch of U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered full dispersion models. 150 151 @keyword folder: The name of the folder for the test data. 152 @type folder: str 153 @keyword model_analyse: The name of the model which will be tested. 154 @type model_analyse: str 155 """ 156 157 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 158 159 # Data. 160 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22146_unpacking_r2a_r2b_cluster'+sep+folder 161 162 ## Experiments 163 # Exp 1 164 sfrq_1 = 500.0*1E6 165 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 166 time_T2_1 = 0.05 167 ncycs_1 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 50] 168 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 169 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 170 r2eff_errs_1 = [0.0] * len(ncycs_1) 171 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 172 173 sfrq_2 = 600.0*1E6 174 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 175 time_T2_2 = 0.06 176 ncycs_2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 40, 60] 177 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 178 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 179 r2eff_errs_2 = [0.0] * len(ncycs_2) 180 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 181 182 sfrq_3 = 700.0*1E6 183 r20_key_3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_3) 184 time_T2_3 = 0.07 185 ncycs_3 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 50, 70] 186 # Here you define the direct R2eff errors (rad/s), as being added or subtracted for the created R2eff point in the corresponding ncyc cpmg frequence. 187 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05] 188 r2eff_errs_3 = [0.0] * len(ncycs_3) 189 exp_3 = [sfrq_3, time_T2_3, ncycs_3, r2eff_errs_3] 190 191 # Collect all exps 192 exps = [exp_1, exp_2, exp_3] 193 194 R20 = [5.1, 5.2, 5.3, 10.1, 10.2, 10.3, 6.1, 6.2, 6.3, 11.1, 11.2, 11.3, 7.1, 7.2, 7.3, 12.1, 12.2, 12.3, 8.1, 8.2, 8.3, 13.1, 13.2, 13.3] 195 dw_arr = [1.0, 2.0, 3.0, 4.0] 196 pA_arr = [0.9] 197 kex_arr = [1000.] 198 199 spins = [ 200 ['Ala', 1, 'N', {'r2a': {r20_key_1: R20[0], r20_key_2: R20[1], r20_key_3: R20[2]}, 'r2b': {r20_key_1: R20[3], r20_key_2: R20[4], r20_key_3: R20[5]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[0]}], 201 ['Ala', 2, 'N', {'r2a': {r20_key_1: R20[6], r20_key_2: R20[7], r20_key_3: R20[8]}, 'r2b': {r20_key_1: R20[9], r20_key_2: R20[10], r20_key_3: R20[11]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[1]}], 202 ['Ala', 3, 'N', {'r2a': {r20_key_1: R20[12], r20_key_2: R20[13], r20_key_3: R20[14]}, 'r2b': {r20_key_1: R20[15], r20_key_2: R20[16], r20_key_3: R20[17]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[2]}], 203 ['Ala', 4, 'N', {'r2a': {r20_key_1: R20[18], r20_key_2: R20[19], r20_key_3: R20[20]}, 'r2b': {r20_key_1: R20[21], r20_key_2: R20[22], r20_key_3: R20[23]}, 'kex': kex_arr[0], 'pA': pA_arr[0], 'dw': dw_arr[3]}], 204 ] 205 206 # Create the data pipe. 207 pipe_name = 'base pipe' 208 pipe_type = 'relax_disp' 209 pipe_bundle = 'relax_disp' 210 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type, bundle = pipe_bundle) 211 212 # Generate the sequence. 213 for res_name, res_num, spin_name, params in spins: 214 self.interpreter.spin.create(res_name=res_name, res_num=res_num, spin_name=spin_name) 215 216 # Set isotope 217 self.interpreter.spin.isotope('15N', spin_id='@N') 218 219 # Now loop over the experiments, to set the variables in relax. 220 exp_ids = [] 221 for exp_i in exps: 222 sfrq, time_T2, ncycs, r2eff_errs = exp_i 223 exp_id = 'CPMG_%3.1f' % (sfrq/1E6) 224 exp_ids.append(exp_id) 225 226 ids = [] 227 for ncyc in ncycs: 228 nu_cpmg = ncyc / time_T2 229 cur_id = '%s_%.1f' % (exp_id, nu_cpmg) 230 ids.append(cur_id) 231 232 # Set the spectrometer frequency. 233 self.interpreter.spectrometer.frequency(id=cur_id, frq=sfrq) 234 235 # Set the experiment type. 236 self.interpreter.relax_disp.exp_type(spectrum_id=cur_id, exp_type=EXP_TYPE_CPMG_SQ) 237 238 # Set the relaxation dispersion CPMG constant time delay T (in s). 239 self.interpreter.relax_disp.relax_time(spectrum_id=cur_id, time=time_T2) 240 241 # Set the relaxation dispersion CPMG frequencies. 242 self.interpreter.relax_disp.cpmg_setup(spectrum_id=cur_id, cpmg_frq=nu_cpmg) 243 244 print("\n\nThe experiment IDs are %s." % cdp.spectrum_ids) 245 246 ### Now do fitting. 247 # Change pipe. 248 249 pipe_name_MODEL = "%s_%s"%(pipe_name, model_analyse) 250 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_MODEL, bundle_to = pipe_bundle) 251 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 252 253 # Now read data in. 254 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 255 exp_id = exp_ids[mi] 256 exp_i = exps[mi] 257 sfrq, time_T2, ncycs, r2eff_errs = exp_i 258 259 # Then loop over the spins. 260 for res_name, res_num, spin_name, params in spins: 261 cur_spin_id = ":%i@%s"%(res_num, spin_name) 262 263 # Define file name 264 file_name = "%s%s.txt" % (exp_id, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 265 266 # Read in the R2eff file to put into spin structure. 267 self.interpreter.relax_disp.r2eff_read_spin(id=exp_id, spin_id=cur_spin_id, file=file_name, dir=data_path, disp_point_col=1, data_col=2, error_col=3) 268 269 # Then select model. 270 self.interpreter.relax_disp.select_model(model=model_analyse) 271 272 # Then cluster 273 self.interpreter.relax_disp.cluster('model_cluster', ":1-100") 274 275 # Grid search 276 low_arr = R20 + dw_arr + pA_arr + kex_arr 277 self.interpreter.minimise.grid_search(lower=low_arr, upper=low_arr, inc=1, constraints=True, verbosity=1) 278 279 # Then loop over the defined spins and read the parameters. 280 for i in range(len(spins)): 281 res_name, res_num, spin_name, params = spins[i] 282 cur_spin_id = ":%i@%s"%(res_num, spin_name) 283 cur_spin = return_spin(cur_spin_id) 284 285 for mo_param in cur_spin.params: 286 print(mo_param) 287 # The R2 is a dictionary, depending on spectrometer frequency. 288 if isinstance(getattr(cur_spin, mo_param), dict): 289 for key, val in list(getattr(cur_spin, mo_param).items()): 290 should_be = params[mo_param][key] 291 print(cur_spin.model, res_name, cur_spin_id, mo_param, key, float(val), should_be) 292 self.assertAlmostEqual(val, should_be) 293 else: 294 should_be = float(params[mo_param]) 295 val = getattr(cur_spin, mo_param) 296 print(cur_spin.model, res_name, cur_spin_id, mo_param, val, should_be) 297 self.assertAlmostEqual(val, should_be) 298 299 # Test chi2. 300 # At this point the chi-squared value at the solution should be zero, as the relaxation data was created with the same parameter values. 301 self.assertAlmostEqual(cur_spin.chi2, 0.0, places = places)
302 303
304 - def setup_r1rho_kjaergaard(self, cluster_ids=[], read_R1=True):
305 """Set up the data for the test_r1rho_kjaergaard_*() system tests.""" 306 307 # The path to the data files. 308 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 309 310 # Set pipe name, bundle and type. 311 ds.pipe_name = 'base pipe' 312 ds.pipe_bundle = 'relax_disp' 313 ds.pipe_type = 'relax_disp' 314 315 # Create the data pipe. 316 self.interpreter.pipe.create(pipe_name=ds.pipe_name, bundle=ds.pipe_bundle, pipe_type=ds.pipe_type) 317 318 # Read the spins. 319 self.interpreter.spectrum.read_spins(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 320 321 # Name the isotope for field strength scaling. 322 self.interpreter.spin.isotope(isotope='15N') 323 324 # Set number of experiments to be used. 325 NR_exp = 70 326 327 # Load the experiments settings file. 328 expfile = open(data_path+sep+'exp_parameters_sort.txt', 'r') 329 expfileslines = expfile.readlines()[:NR_exp] 330 expfile.close() 331 332 # In MHz 333 yOBS = 81.050 334 # In ppm 335 yCAR = 118.078 336 centerPPM_N15 = yCAR 337 338 ## Read the chemical shift data. 339 self.interpreter.chemical_shift.read(file='1_0_46_0_max_standard.ser', dir=data_path+sep+'peak_lists') 340 341 # The lock power to field, has been found in an calibration experiment. 342 spin_lock_field_strengths_Hz = {'35': 431.0, '39': 651.2, '41': 800.5, '43': 984.0, '46': 1341.11, '48': 1648.5} 343 344 # Apply spectra settings. 345 # Count settings 346 j = 0 347 for i in range(len(expfileslines)): 348 line = expfileslines[i] 349 if line[0] == "#": 350 continue 351 else: 352 # DIRN I deltadof2 dpwr2slock ncyc trim ss sfrq 353 DIRN = line.split()[0] 354 I = int(line.split()[1]) 355 deltadof2 = line.split()[2] 356 dpwr2slock = line.split()[3] 357 ncyc = int(line.split()[4]) 358 trim = float(line.split()[5]) 359 ss = int(line.split()[6]) 360 set_sfrq = float(line.split()[7]) 361 apod_rmsd = float(line.split()[8]) 362 spin_lock_field_strength = spin_lock_field_strengths_Hz[dpwr2slock] 363 364 # Calculate spin_lock time 365 time_sl = 2*ncyc*trim 366 367 # Define file name for peak list. 368 FNAME = "%s_%s_%s_%s_max_standard.ser"%(I, deltadof2, dpwr2slock, ncyc) 369 sp_id = "%s_%s_%s_%s"%(I, deltadof2, dpwr2slock, ncyc) 370 371 # Load the peak intensities. 372 self.interpreter.spectrum.read_intensities(file=FNAME, dir=data_path+sep+'peak_lists', spectrum_id=sp_id, int_method='height') 373 374 # Set the peak intensity errors, as defined as the baseplane RMSD. 375 self.interpreter.spectrum.baseplane_rmsd(error=apod_rmsd, spectrum_id=sp_id) 376 377 # Set the relaxation dispersion experiment type. 378 self.interpreter.relax_disp.exp_type(spectrum_id=sp_id, exp_type='R1rho') 379 380 # Set The spin-lock field strength, nu1, in Hz 381 self.interpreter.relax_disp.spin_lock_field(spectrum_id=sp_id, field=spin_lock_field_strength) 382 383 # Calculating the spin-lock offset in ppm, from offsets values provided in Hz. 384 frq_N15_Hz = yOBS * 1E6 385 offset_ppm_N15 = float(deltadof2) / frq_N15_Hz * 1E6 386 omega_rf_ppm = centerPPM_N15 + offset_ppm_N15 387 388 # Set The spin-lock offset, omega_rf, in ppm. 389 self.interpreter.relax_disp.spin_lock_offset(spectrum_id=sp_id, offset=omega_rf_ppm) 390 391 # Set the relaxation times (in s). 392 self.interpreter.relax_disp.relax_time(spectrum_id=sp_id, time=time_sl) 393 394 # Set the spectrometer frequency. 395 self.interpreter.spectrometer.frequency(id=sp_id, frq=set_sfrq, units='MHz') 396 397 # Add to counter 398 j += 1 399 400 401 print("Testing the number of settings") 402 print("Number of settings iterations is: %s. Number of cdp.exp_type is: %s"%(i, len(cdp.exp_type))) 403 self.assertEqual(70, len(expfileslines)) 404 self.assertEqual(69, j) 405 self.assertEqual(69, len(cdp.exp_type)) 406 407 # Cluster spins 408 for curspin in cluster_ids: 409 print("Adding spin %s to cluster"%curspin) 410 self.interpreter.relax_disp.cluster('model_cluster', curspin) 411 412 # De-select for analysis those spins who have not been clustered 413 for free_spin in cdp.clustering['free spins']: 414 print("Deselecting free spin %s"%free_spin) 415 self.interpreter.deselect.spin(spin_id=free_spin, change_all=False) 416 417 418 #Paper reference values 419 # Resi Resn R1_rad_s R1err_rad_s R2_rad_s R2err_rad_s kEX_rad_s kEXerr_rad_s phi_rad2_s2 phierr_rad2_s2 phi_ppm2 phierr_ppm2 420 # Scaling rad2_s2 to ppm2: scaling_rad2_s2 = frequency_to_ppm(frq=1/(2*pi), B0=cdp.spectrometer_frq_list[0], isotope='15N')**2 = 3.85167990165e-06 421 ds.ref = dict() 422 ds.ref[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 423 ds.ref[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 424 ds.ref[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 425 ds.ref[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 426 ds.ref[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 427 ds.ref[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 428 ds.ref[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 429 ds.ref[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 430 ds.ref[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 431 ds.ref[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 432 ds.ref[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 433 ds.ref[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 434 ds.ref[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 435 ds.ref[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 436 ds.ref[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 437 438 ds.guess = dict() 439 ds.guess[':13@N'] = [13, 'L13N-HN', 1.32394, 0.14687, 8.16007, 1.01237, 13193.82986, 2307.09152, 58703.06446, 22413.09854, 0.2261054135, 0.0863280812] 440 ds.guess[':15@N'] = [15, 'R15N-HN', 1.34428, 0.14056, 7.83256, 0.67559, 13193.82986, 2307.09152, 28688.33492, 13480.72253, 0.110498283, 0.051923428] 441 ds.guess[':16@N'] = [16, 'T16N-HN', 1.71514, 0.13651, 17.44216, 0.98583, 13193.82986, 2307.09152, 57356.77617, 21892.44205, 0.220919942, 0.084322679] 442 ds.guess[':25@N'] = [25, 'Q25N-HN', 1.82412, 0.15809, 9.09447, 2.09215, 13193.82986, 2307.09152, 143111.13431, 49535.80302, 0.5512182797, 0.1907960569] 443 ds.guess[':26@N'] = [26, 'Q26N-HN', 1.45746, 0.14127, 10.22801, 0.67116, 13193.82986, 2307.09152, 28187.06876, 13359.01615, 0.1085675662, 0.051454654] 444 ds.guess[':28@N'] = [28, 'Q28N-HN', 1.48095, 0.14231, 10.33552, 0.691, 13193.82986, 2307.09152, 30088.0686, 13920.25654, 0.1158896091, 0.0536163723] 445 ds.guess[':39@N'] = [39, 'L39N-HN', 1.46094, 0.14514, 8.02194, 0.84649, 13193.82986, 2307.09152, 44130.18538, 18104.55064, 0.1699753481, 0.0697329338] 446 ds.guess[':40@N'] = [40, 'M40N-HN', 1.21381, 0.14035, 12.19112, 0.81418, 13193.82986, 2307.09152, 41834.90493, 17319.92156, 0.1611346625, 0.0667107938] 447 ds.guess[':41@N'] = [41, 'A41N-HN', 1.29296, 0.14286, 9.29941, 0.66246, 13193.82986, 2307.09152, 26694.8921, 13080.66782, 0.1028201794, 0.0503825453] 448 ds.guess[':43@N'] = [43, 'F43N-HN', 1.33626, 0.14352, 12.73816, 1.17386, 13193.82986, 2307.09152, 70347.63797, 26648.30524, 0.2709565833, 0.1026407417] 449 ds.guess[':44@N'] = [44, 'I44N-HN', 1.28487, 0.1462, 12.70158, 1.52079, 13193.82986, 2307.09152, 95616.20461, 35307.79817, 0.3682830136, 0.1359943366] 450 ds.guess[':45@N'] = [45, 'K45N-HN', 1.59227, 0.14591, 9.54457, 0.95596, 13193.82986, 2307.09152, 53849.7826, 21009.89973, 0.2074121253, 0.0809234085] 451 ds.guess[':49@N'] = [49, 'A49N-HN', 1.38521, 0.14148, 4.44842, 0.88647, 13193.82986, 2307.09152, 40686.65286, 18501.20774, 0.1567119631, 0.07126073] 452 ds.guess[':52@N'] = [52, 'V52N-HN', 1.57531, 0.15042, 6.51945, 1.43418, 13193.82986, 2307.09152, 93499.92172, 33233.23039, 0.3601317693, 0.1280037656] 453 ds.guess[':53@N'] = [53, 'A53N-HN', 1.27214, 0.13823, 4.0705, 0.85485, 13193.82986, 2307.09152, 34856.18636, 17505.02393, 0.1342548725, 0.0674237488] 454 455 # Assign guess values. 456 for spin, spin_id in spin_loop(return_id=True): 457 if spin_id in cluster_ids: 458 print("spin_id %s in cluster ids"%(spin_id)) 459 spin.kex = ds.guess[spin_id][6] 460 spin.phi_ex = ds.guess[spin_id][10] 461 else: 462 print("spin_id %s NOT in cluster ids"%(spin_id)) 463 464 if read_R1: 465 # Read the R1 data 466 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7)
467 468
469 - def setup_hansen_cpmg_data(self, model=None):
470 """Set up the data for the test_hansen_cpmg_data_*() system tests. 471 472 @keyword model: The name of the model which will be tested. 473 @type model: str 474 """ 475 476 # Create the data pipe and load the base data. 477 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 478 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 479 self.interpreter.results.read(data_path+sep+'base_pipe') 480 self.interpreter.deselect.spin(':4') 481 482 # Set the nuclear isotope data. 483 self.interpreter.spin.isotope('15N') 484 485 # Create the R2eff data pipe and load the results. 486 self.interpreter.pipe.create(pipe_name='R2eff - relax_disp', pipe_type='relax_disp') 487 self.interpreter.pipe.switch(pipe_name='R2eff - relax_disp') 488 self.interpreter.results.read(data_path+sep+'r2eff_pipe') 489 self.interpreter.deselect.spin(':4') 490 491 # The model data pipe. 492 pipe_name = "%s - relax_disp" % model 493 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 494 self.interpreter.pipe.switch(pipe_name=pipe_name) 495 496 # Set the model. 497 self.interpreter.relax_disp.select_model(model=model) 498 499 # Copy the data. 500 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to=pipe_name, param='r2eff')
501 502
503 - def setup_kteilum_fmpoulsen_makke_cpmg_data(self, model=None, expfolder=None):
504 """Set up the data for the test_kteilum_fmpoulsen_makke_cpmg_data_*() system tests. 505 506 @keyword model: The name of the model which will be tested. 507 @type model: str 508 """ 509 510 # Create the data pipe and load the base data. 511 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder 512 self.interpreter.pipe.create(pipe_name='base pipe', pipe_type='relax_disp') 513 self.interpreter.results.read(data_path+sep+'ini_setup_trunc') 514 515 # Create the R2eff data pipe and load the results. 516 self.interpreter.pipe.create(pipe_name='R2eff', pipe_type='relax_disp') 517 self.interpreter.pipe.switch(pipe_name='R2eff') 518 self.interpreter.results.read(data_path+sep+'r2eff_pipe_trunc') 519 520 # The model data pipe. 521 pipe_name = "%s - relax_disp" % model 522 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 523 self.interpreter.pipe.switch(pipe_name=pipe_name) 524 525 # Set the model. 526 self.interpreter.relax_disp.select_model(model=model) 527 528 # Copy the data. 529 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff')
530 531
532 - def setup_korzhnev_2005_data(self, data_list=[]):
533 """Set up the data for the test_korzhnev_2005_data_*() system tests using the 'NS MMQ 2-site' model. 534 535 This loads the proton-heteronuclear SQ, ZQ, DQ, and MQ (MMQ) data from: 536 537 - Dmitry M. Korzhnev, Philipp Neudecker, Anthony Mittermaier, Vladislav Yu. Orekhov, and Lewis E. Kay (2005) Multiple-site exchange in proteins studied with a suite of six NMR relaxation dispersion experiments: An application to the folding of a Fyn SH3 domain mutant. 127, 15602-15611 (U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}). 538 539 It consists of the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 540 541 542 @keyword data_list: The list of data to load. It can contain 'SQ', '1H SQ', 'ZQ', 'DQ', 'MQ', and '1H MQ'. 543 @type data_list: list of str 544 """ 545 546 # Create the data pipe and load the base data. 547 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 548 self.interpreter.pipe.create(pipe_name='Korzhnev et al., 2005', pipe_type='relax_disp') 549 550 # Create the spin system. 551 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 552 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 553 self.interpreter.spin.element('H', spin_id='@H') 554 self.interpreter.spin.element('N', spin_id='@N') 555 self.interpreter.spin.isotope('1H', spin_id='@H') 556 self.interpreter.spin.isotope('15N', spin_id='@N') 557 558 # Define the magnetic dipole-dipole relaxation interaction. 559 self.interpreter.interatom.define(spin_id1=':9@N', spin_id2=':9@H', direct_bond=True) 560 561 # The spectral data - experiment ID, R2eff file name, experiment type, spin ID string, spectrometer frequency in Hertz, relaxation time. 562 data = [ 563 ['1H SQ', '1H_SQ_CPMG_500_MHz', 'hs_500.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 500e6, 0.03], 564 ['1H SQ', '1H_SQ_CPMG_600_MHz', 'hs_600.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 600e6, 0.03], 565 ['1H SQ', '1H_SQ_CPMG_800_MHz', 'hs_800.res', EXP_TYPE_CPMG_PROTON_SQ, ':9@H', 800e6, 0.03], 566 ['SQ', '15N_SQ_CPMG_500_MHz', 'ns_500.res', EXP_TYPE_CPMG_SQ, ':9@N', 500e6, 0.04], 567 ['SQ', '15N_SQ_CPMG_600_MHz', 'ns_600.res', EXP_TYPE_CPMG_SQ, ':9@N', 600e6, 0.04], 568 ['SQ', '15N_SQ_CPMG_800_MHz', 'ns_800.res', EXP_TYPE_CPMG_SQ, ':9@N', 800e6, 0.04], 569 ['DQ', '15N_DQ_CPMG_500_MHz', 'dq_500.res', EXP_TYPE_CPMG_DQ, ':9@N', 500e6, 0.03], 570 ['DQ', '15N_DQ_CPMG_600_MHz', 'dq_600.res', EXP_TYPE_CPMG_DQ, ':9@N', 600e6, 0.03], 571 ['DQ', '15N_DQ_CPMG_800_MHz', 'dq_800.res', EXP_TYPE_CPMG_DQ, ':9@N', 800e6, 0.03], 572 ['ZQ', '15N_ZQ_CPMG_500_MHz', 'zq_500.res', EXP_TYPE_CPMG_ZQ, ':9@N', 500e6, 0.03], 573 ['ZQ', '15N_ZQ_CPMG_600_MHz', 'zq_600.res', EXP_TYPE_CPMG_ZQ, ':9@N', 600e6, 0.03], 574 ['ZQ', '15N_ZQ_CPMG_800_MHz', 'zq_800.res', EXP_TYPE_CPMG_ZQ, ':9@N', 800e6, 0.03], 575 ['1H MQ', '1H_MQ_CPMG_500_MHz', 'hm_500.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 500e6, 0.02], 576 ['1H MQ', '1H_MQ_CPMG_600_MHz', 'hm_600.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 600e6, 0.02], 577 ['1H MQ', '1H_MQ_CPMG_800_MHz', 'hm_800.res', EXP_TYPE_CPMG_PROTON_MQ, ':9@H', 800e6, 0.02], 578 ['MQ', '15N_MQ_CPMG_500_MHz', 'nm_500.res', EXP_TYPE_CPMG_MQ, ':9@N', 500e6, 0.02], 579 ['MQ', '15N_MQ_CPMG_600_MHz', 'nm_600.res', EXP_TYPE_CPMG_MQ, ':9@N', 600e6, 0.02], 580 ['MQ', '15N_MQ_CPMG_800_MHz', 'nm_800.res', EXP_TYPE_CPMG_MQ, ':9@N', 800e6, 0.02] 581 ] 582 cpmg_frqs_1h_sq = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 583 cpmg_frqs_sq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 584 cpmg_frqs_dq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 585 cpmg_frqs_zq = [33.0, 67.0, 133.0, 200.0, 267.0, 333.0, 400.0, 467.0, 533.0, 667.0, 800.0, 933.0, 1067.0] 586 cpmg_frqs_1h_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 400.0, 500.0, 600.0, 700.0, 800.0, 1000.0, 1500.0, 2000.0, 2500.0] 587 cpmg_frqs_mq = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 588 589 # Loop over the files, reading in the data. 590 for data_type, id, file, exp_type, spin_id, H_frq, relax_time in data: 591 # Skip undesired data. 592 if data_type not in data_list: 593 continue 594 595 # Alias the CPMG frequencies. 596 if data_type == 'SQ': 597 cpmg_frqs = cpmg_frqs_sq 598 elif data_type == '1H SQ': 599 cpmg_frqs = cpmg_frqs_1h_sq 600 elif data_type == 'DQ': 601 cpmg_frqs = cpmg_frqs_dq 602 elif data_type == 'ZQ': 603 cpmg_frqs = cpmg_frqs_zq 604 elif data_type == '1H MQ': 605 cpmg_frqs = cpmg_frqs_1h_mq 606 elif data_type == 'MQ': 607 cpmg_frqs = cpmg_frqs_mq 608 609 # Loop over each CPMG frequency. 610 for cpmg_frq in cpmg_frqs: 611 # The id. 612 new_id = "%s_%s" % (id, cpmg_frq) 613 614 # Set the NMR field strength. 615 self.interpreter.spectrometer.frequency(id=new_id, frq=H_frq) 616 617 # Set the relaxation dispersion experiment type. 618 self.interpreter.relax_disp.exp_type(spectrum_id=new_id, exp_type=exp_type) 619 620 # Relaxation dispersion CPMG constant time delay T (in s). 621 self.interpreter.relax_disp.relax_time(spectrum_id=new_id, time=relax_time) 622 623 # Set the CPMG frequency. 624 self.interpreter.relax_disp.cpmg_setup(spectrum_id=new_id, cpmg_frq=cpmg_frq) 625 626 # Read the R2eff data. 627 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 628 629 # Change the model. 630 self.interpreter.relax_disp.select_model('NS MMQ 2-site')
631 632
633 - def setup_sod1wt_t25(self, pipe_name, pipe_type, pipe_name_r2eff, select_spin_index):
634 """Setup of data SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 635 636 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 637 'SOD1-WT' CPMG data to the CR72 dispersion model. 638 639 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 640 Data is for experiment at 25 degree Celcius. 641 """ 642 643 # Create the data pipe and load the base data. 644 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'sod1wt_t25' 645 646 # Set experiment settings. sfrq, time_T2, ncyc 647 Exps = [ 648 ["600MHz", "Z_A", 599.8908617*1E6, 0.06, [28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 50, 18, 40, 6, 12, 0, 24], ["Z_A1", "Z_A15"] ], 649 ["500MHz", "Z_B", 499.862139*1E6, 0.04, [20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0], ["Z_B1", "Z_B18"] ] ] 650 651 # Create base pipe 652 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 653 654 # Loop throug experiments 655 id_lists = [] 656 for folder, key, sfrq, time_T2, ncycs, rep_ncyss in Exps: 657 # Read spins 658 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 659 self.interpreter.spectrum.read_spins(file="128_FT.ser", dir=data_path+sep+folder) 660 661 # Make spectrum id list 662 id_list = list(key+str(i) for i in range(len(ncycs))) 663 id_lists.append(id_list) 664 665 # Read intensities 666 self.interpreter.spectrum.read_intensities(file="128_FT.ser", dir=data_path+sep+folder, int_method='height', spectrum_id=id_list, int_col=list(range(len(id_list))) ) 667 668 # Loop over experiments 669 for i in range(len(ncycs)): 670 ncyc = ncycs[i] 671 vcpmg = ncyc/time_T2 672 673 # Test if spectrum is a reference 674 if float(vcpmg) == 0.0: 675 vcpmg = None 676 else: 677 vcpmg = round(float(vcpmg), 3) 678 679 # Set current id 680 current_id = id_list[i] 681 682 # Set the current experiment type. 683 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 684 685 # Set the NMR field strength of the spectrum. 686 self.interpreter.spectrometer.frequency(id=current_id, frq=sfrq, units='Hz') 687 688 # Relaxation dispersion CPMG constant time delay T (in s). 689 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 690 691 # Set the relaxation dispersion CPMG frequencies. 692 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 693 694 # Define replicated 695 self.interpreter.spectrum.replicated(spectrum_ids=Exps[0][5]) 696 self.interpreter.spectrum.replicated(spectrum_ids=Exps[1][5]) 697 698 # Perform error analysis 699 self.interpreter.spectrum.error_analysis(subset=id_lists[0]) 700 self.interpreter.spectrum.error_analysis(subset=id_lists[1]) 701 702 # Define isotope 703 self.interpreter.spin.isotope(isotope='15N') 704 705 ############# 706 707 # Define the 64 residues which was used for Global fitting 708 glob_assn = ["G10N-H", "D11N-H", "Q15N-H", "G16N-H", "G37N-H", "G41N-H", "L42N-H", "H43N-H", "H46N-H", "V47N-H", "E49N-H", 709 "E50N-H", "E51N-H", "N53N-H", "T54N-H", "G56N-H", "C57N-H", "T58N-H", "G61N-H", "H63aN-H", "F64aN-H", "N65aN-H", 710 "L67N-H", "S68N-H", "K70N-H", "G72N-H", "G73N-H", "K75N-H", "E78N-H", "R79N-H", "H80N-H", "V81N-H", "G82N-H", 711 "G85N-H", "N86N-H", "V87N-H", "S102N-H", "V103N-H", "I104N-H", "S105N-H", "A111N-H", "I112N-H", "R115N-H", 712 "V118N-H", "E121N-H", "A123N-H", "L126N-H", "G127N-H", "K128N-H", "G129N-H", "G130N-H", "N131N-H", "E133N-H", 713 "S134N-H", "T135N-H", "T137N-H", "G138N-H", "N139N-H", "A140N-H", "G141N-H", "S142N-H", "R143N-H", "C146N-H", "G147N-H"] 714 715 # Test number of global 716 self.assertEqual(64, len(glob_assn )) 717 718 ## Turn assignments into relax spin ids. 719 # Define regular expression search 720 r = re.compile("([a-zA-Z]+)([0-9]+)([a-zA-Z]+)") 721 722 # Create list to hold regular expression search 723 relax_glob_ids = [] 724 725 # Loop over assignments 726 for assn in glob_assn: 727 # Make match for the regular search 728 m = r.match(assn) 729 # Convert to relax spin string 730 relax_string = ":%s@%s"%(m.group(2), m.group(3)) 731 732 # Save the relax spin string and the regular search 733 relax_glob_ids.append([m.group(0), m.group(1), m.group(2), m.group(3), relax_string]) 734 735 ############# Deselect all spins, and select few spins 736 737 ## Deselect all spins, and select a few for analysis 738 self.interpreter.deselect.all() 739 740 # Select few spins 741 for i in select_spin_index: 742 self.interpreter.select.spin(spin_id=relax_glob_ids[i][4], change_all=False) 743 744 ############## 745 746 # Prepare for R2eff calculation 747 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 748 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 749 750 # Select model for points calculation 751 MODEL = "R2eff" 752 self.interpreter.relax_disp.select_model(model=MODEL) 753 # Calculate R2eff values 754 self.interpreter.minimise.calculate(verbosity=1)
755 756
757 - def setup_missing_r1_spins(self):
758 """Function for setting up a few spins for the given pipe.""" 759 760 # Path to file. 761 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 762 763 # File with spins. 764 file = open(data_path+sep+'R1_fitted_values.txt') 765 lines = file.readlines() 766 file.close() 767 768 for i, line in enumerate(lines): 769 # Make the string test 770 line_split = line.split() 771 772 if line_split[0] == "#": 773 continue 774 775 mol_name = line_split[0] 776 mol_name = None 777 res_num = int(line_split[1]) 778 res_name = line_split[2] 779 spin_num = line_split[3] 780 spin_num = None 781 spin_name = line_split[4] 782 783 # Create the spin. 784 self.interpreter.spin.create(spin_name=spin_name, spin_num=spin_num, res_name=res_name, res_num=res_num, mol_name=mol_name)
785 786
787 - def setup_tp02_data_to_ns_r1rho_2site(self, clustering=False):
788 """Setup data for the test of relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 789 790 # Reset. 791 self.interpreter.reset() 792 793 # Create the data pipe and load the base data. 794 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 795 self.interpreter.state.load(data_path+sep+'r2eff_values') 796 797 # The model data pipe. 798 model = 'NS R1rho 2-site' 799 pipe_name = "%s - relax_disp" % model 800 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 801 self.interpreter.pipe.switch(pipe_name=pipe_name) 802 803 # Set the model. 804 self.interpreter.relax_disp.select_model(model=model) 805 806 # Copy the data. 807 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 808 809 # Alias the spins. 810 spin1 = cdp.mol[0].res[0].spin[0] 811 spin2 = cdp.mol[0].res[1].spin[0] 812 813 # The R20 keys. 814 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 815 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 816 817 # Set the initial parameter values. 818 spin1.r2 = {r20_key1: 9.9963793866185, r20_key2: 15.0056724422684} 819 spin1.pA = 0.779782428085762 820 spin1.dw = 7.57855284496424 821 spin1.kex = 1116.7911285203 822 spin2.r2 = {r20_key1: 11.9983346935434, r20_key2: 18.0076097513337} 823 spin2.pA = 0.826666229688602 824 spin2.dw = 9.5732624231366 825 spin2.kex = 1380.46162655657 826 827 # Test the values when clustering. 828 if clustering: 829 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-100") 830 831 # Low precision optimisation. 832 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 833 834 # Printout. 835 print("\n\nOptimised parameters:\n") 836 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 837 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 838 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 839 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 840 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 841 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 842 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2))
843 844
845 - def test_baldwin_synthetic(self):
846 """Test synthetic data of Andrew J. Baldwin B14 model whereby the simplification R20A = R20B is assumed. 847 848 Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 849 850 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>} with R20A, R20B = 2. rad/s. 851 """ 852 853 # The path to the data files. 854 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 855 856 # Create pipe 857 pipe_name = 'base pipe' 858 pipe_type = 'relax_disp' 859 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 860 861 # Create base pipe 862 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 863 864 # Generate the sequence. 865 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 866 867 # Define the isotope. 868 self.interpreter.spin.isotope('1H', spin_id='@H') 869 870 # Build the experiment IDs. 871 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 872 ncycs = [2, 4, 8, 10, 20, 40, 500] 873 ids = [] 874 for ncyc in ncycs: 875 ids.append('CPMG_%s' % ncyc) 876 877 print("\n\nThe experiment IDs are %s." % ids) 878 879 # Set up the metadata for the experiments. 880 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 881 sfrq = 200. * 1E6 882 883 # Total time of CPMG block. 884 Trelax = 0.04 885 886 # First set the 887 for i in range(len(ids)): 888 id = ids[i] 889 # Set the spectrometer frequency. 890 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 891 892 # Set the experiment type. 893 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 894 895 # Set the relaxation dispersion CPMG constant time delay T (in s). 896 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 897 898 # Set the relaxation dispersion CPMG frequencies. 899 ncyc = ncycs[i] 900 nu_cpmg = ncyc / Trelax 901 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 902 903 # Prepare for R2eff reading. 904 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 905 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 906 907 # Try reading the R2eff file. 908 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_r2a_eq_r2b_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 909 910 # Check the global data. 911 data = [ 912 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 913 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 914 ['dispersion_points', len(ncycs)], 915 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 916 ['exp_type_list', ['SQ CPMG']], 917 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 918 ['spectrometer_frq_count', 1], 919 ['spectrometer_frq_list', [sfrq]], 920 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 921 ] 922 for name, value in data: 923 # Does it exist? 924 self.assert_(hasattr(cdp, name)) 925 926 # Check the object. 927 obj = getattr(cdp, name) 928 if not isinstance(data, dict): 929 self.assertEqual(obj, value) 930 931 # Check the global dictionary data. 932 else: 933 for id in ids: 934 self.assertEqual(obj[id], value[id]) 935 936 # Check the spin data. 937 n_data = [ 938 [ 50.000000, 10.367900, 0.1], 939 [ 100.000000, 10.146849, 0.1], 940 [ 200.000000, 9.765987, 0.1], 941 [ 250.000000, 9.409789, 0.1], 942 [ 500.000000, 5.829819, 0.1], 943 [ 1000.000000, 3.191928, 0.1], 944 [ 12500.000000, 2.008231, 0.1] 945 ] 946 for disp_point, value, error in n_data: 947 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 948 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 949 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 950 951 # Generate r20 key. 952 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 953 954 ## Now prepare for MODEL calculation. 955 MODEL = "B14" 956 957 # Change pipe. 958 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 959 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 960 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 961 962 # Then select model. 963 self.interpreter.relax_disp.select_model(model=MODEL) 964 965 # Store grid and minimisations results. 966 grid_results = [] 967 mini_results = [] 968 969 # The grid search size (the number of increments per dimension). 970 # If None, use the default values. 971 #GRID = None 972 GRID = 13 973 # Perform Grid Search. 974 if GRID: 975 # Set the R20 parameters in the default grid search using the minimum R2eff value. 976 # This speeds it up considerably. 977 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 978 979 # Then do grid search. 980 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 981 982 # If no Grid search, set the default values. 983 else: 984 for param in MODEL_PARAMS[MODEL]: 985 self.interpreter.value.set(param=param, index=None) 986 # Do a grid search, which will store the chi2 value. 987 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 988 989 # Store result. 990 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 991 grid_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 992 993 ## Now do minimisation. 994 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 995 set_func_tol = 1e-10 996 set_max_iter = 1000 997 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 998 999 # Store result. 1000 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1001 mini_results.append([spin.r2[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1002 1003 # Print results. 1004 for i in range(len(grid_results)): 1005 g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1006 m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1007 print("GRID %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1008 print("MIN %s r2=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1009 1010 # Reference values from Baldwin.py. 1011 # Exchange rate = k+ + k- (s-1) 1012 kex = 1000. 1013 # Fractional population of excited state k+/kex 1014 pb = 0.01 1015 # deltaOmega in ppm 1016 dw_ppm = 2. 1017 #relaxation rate of ground (s-1) 1018 R2g = 2. 1019 #relaxation rate of excited (s-1) 1020 R2e = 2. 1021 1022 # Test the parameters which created the data. 1023 # This is for the 1H spin. 1024 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2[r20_key], R2g, 6) 1025 1026 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1027 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 8) 1028 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex, kex, 3)
1029 1030
1032 """Test synthetic data of Andrew J. Baldwin B14 model. Support requst sr #3154 U{https://gna.org/support/index.php?3154}. 1033 1034 This uses the synthetic data from paper U{DOI: 10.1016/j.jmr.2014.02.023 <http://dx.doi.org/10.1016/j.jmr.2014.02.023>}. 1035 """ 1036 1037 # The path to the data files. 1038 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Baldwin_2014' 1039 1040 # Create pipe 1041 pipe_name = 'base pipe' 1042 pipe_type = 'relax_disp' 1043 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 1044 1045 # Create base pipe 1046 self.interpreter.pipe.create(pipe_name=pipe_name, pipe_type=pipe_type) 1047 1048 # Generate the sequence. 1049 # Generate both a 1H spin, and 15N spin. 1050 self.interpreter.spin.create(res_name='Ala', res_num=1, spin_name='H') 1051 1052 # Define the isotope. 1053 self.interpreter.spin.isotope('1H', spin_id='@H') 1054 1055 # Build the experiment IDs. 1056 # Number of cpmg cycles (1 cycle = delay/180/delay/delay/180/delay) 1057 ncycs = [2, 4, 8, 10, 20, 40, 500] 1058 ids = [] 1059 for ncyc in ncycs: 1060 ids.append('CPMG_%s' % ncyc) 1061 1062 print("\n\nThe experiment IDs are %s." % ids) 1063 1064 # Set up the metadata for the experiments. 1065 # This value is used in Baldwin.py. It is the 1H Larmor frequency. 1066 sfrq = 200. * 1E6 1067 1068 # Total time of CPMG block. 1069 Trelax = 0.04 1070 1071 # First set the 1072 for i in range(len(ids)): 1073 id = ids[i] 1074 # Set the spectrometer frequency. 1075 self.interpreter.spectrometer.frequency(id=id, frq=sfrq) 1076 1077 # Set the experiment type. 1078 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 1079 1080 # Set the relaxation dispersion CPMG constant time delay T (in s). 1081 self.interpreter.relax_disp.relax_time(spectrum_id=id, time=Trelax) 1082 1083 # Set the relaxation dispersion CPMG frequencies. 1084 ncyc = ncycs[i] 1085 nu_cpmg = ncyc / Trelax 1086 self.interpreter.relax_disp.cpmg_setup(spectrum_id=id, cpmg_frq=nu_cpmg) 1087 1088 # Prepare for R2eff reading. 1089 self.interpreter.pipe.copy(pipe_from=pipe_name, pipe_to=pipe_name_r2eff) 1090 self.interpreter.pipe.switch(pipe_name=pipe_name_r2eff) 1091 1092 # Try reading the R2eff file. 1093 self.interpreter.relax_disp.r2eff_read_spin(id="CPMG", file="test_w_error.out", dir=data_path, spin_id=':1@H', disp_point_col=1, data_col=2, error_col=3) 1094 1095 # Check the global data. 1096 data = [ 1097 ['cpmg_frqs', {'CPMG_20': 500.0, 'CPMG_10': 250.0, 'CPMG_40': 1000.0, 'CPMG_4': 100.0, 'CPMG_2': 50.0, 'CPMG_500': 12500.0, 'CPMG_8': 200.0}], 1098 ['cpmg_frqs_list', list(array(ncycs)/Trelax) ], 1099 ['dispersion_points', len(ncycs)], 1100 ['exp_type', {'CPMG_20': 'SQ CPMG', 'CPMG_10': 'SQ CPMG', 'CPMG_40': 'SQ CPMG', 'CPMG_4': 'SQ CPMG', 'CPMG_2': 'SQ CPMG', 'CPMG_500': 'SQ CPMG', 'CPMG_8': 'SQ CPMG'}], 1101 ['exp_type_list', ['SQ CPMG']], 1102 ['spectrometer_frq', {'CPMG_20': 200000000.0, 'CPMG_10': 200000000.0, 'CPMG_40': 200000000.0, 'CPMG_4': 200000000.0, 'CPMG_2': 200000000.0, 'CPMG_500': 200000000.0, 'CPMG_8': 200000000.0}], 1103 ['spectrometer_frq_count', 1], 1104 ['spectrometer_frq_list', [sfrq]], 1105 ['spectrum_ids', ['CPMG_2', 'CPMG_4', 'CPMG_8', 'CPMG_10', 'CPMG_20', 'CPMG_40', 'CPMG_500']] 1106 ] 1107 for name, value in data: 1108 # Does it exist? 1109 self.assert_(hasattr(cdp, name)) 1110 1111 # Check the object. 1112 obj = getattr(cdp, name) 1113 if not isinstance(data, dict): 1114 self.assertEqual(obj, value) 1115 1116 # Check the global dictionary data. 1117 else: 1118 for id in ids: 1119 self.assertEqual(obj[id], value[id]) 1120 1121 # Check the spin data. 1122 n_data = [ 1123 [ 50.000000, 10.286255, 0.1], 1124 [ 100.000000, 10.073083, 0.1], 1125 [ 200.000000, 9.692746, 0.1], 1126 [ 250.000000, 9.382441, 0.1], 1127 [ 500.000000, 6.312396, 0.1], 1128 [ 1000.000000, 3.957029, 0.1], 1129 [ 12500.000000, 2.880420, 0.1] 1130 ] 1131 for disp_point, value, error in n_data: 1132 id = 'sq_cpmg_200.00000000_0.000_%.3f' % disp_point 1133 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 1134 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 1135 1136 # Generate r20 key. 1137 r20_key = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq) 1138 1139 ## Now prepare for MODEL calculation. 1140 MODEL = "B14 full" 1141 1142 # Change pipe. 1143 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 1144 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 1145 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 1146 1147 # Then select model. 1148 self.interpreter.relax_disp.select_model(model=MODEL) 1149 1150 # Store grid and minimisations results. 1151 grid_results = [] 1152 mini_results = [] 1153 clust_results = [] 1154 1155 # The grid search size (the number of increments per dimension). 1156 # If None, use the default values. 1157 #GRID = None 1158 GRID = 13 1159 # Perform Grid Search. 1160 if GRID: 1161 # Set the R20 parameters in the default grid search using the minimum R2eff value. 1162 # This speeds it up considerably. 1163 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 1164 1165 # Then do grid search. 1166 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID, constraints=True, verbosity=1) 1167 1168 # If no Grid search, set the default values. 1169 else: 1170 for param in MODEL_PARAMS[MODEL]: 1171 self.interpreter.value.set(param=param, index=None) 1172 # Do a grid search, which will store the chi2 value. 1173 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=1, constraints=True, verbosity=1) 1174 1175 # Store result. 1176 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1177 grid_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1178 1179 ## Now do minimisation. 1180 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 1181 set_func_tol = 1e-11 1182 set_max_iter = 10000 1183 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1184 1185 # Store result. 1186 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1187 mini_results.append([spin.r2a[r20_key], spin.r2b[r20_key], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 1188 1189 print("\n# Now print before and after minimisation-\n") 1190 1191 # Print results. 1192 for i in range(len(grid_results)): 1193 g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 1194 m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 1195 print("GRID %s r2a=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2a, g_r2b, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 1196 print("MIN %s r2b=%2.4f r2b=%2.4f dw=%1.4f pA=%1.4f kex=%3.4f chi2=%3.4f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2a, m_r2b, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 1197 1198 # Reference values from Baldwin.py. 1199 # Exchange rate = k+ + k- (s-1) 1200 kex = 1000. 1201 # Fractional population of excited state k+/kex 1202 pb = 0.01 1203 # deltaOmega in ppm 1204 dw_ppm = 2. 1205 #relaxation rate of ground (s-1) 1206 R2g = 2. 1207 #relaxation rate of excited (s-1) 1208 R2e = 100. 1209 1210 # Test the parameters which created the data. 1211 # This is for the 1H spin. 1212 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2a[r20_key], R2g, 3) 1213 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].r2b[r20_key]/100, R2e/100, 3) 1214 1215 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].dw, dw_ppm, 6) 1216 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].pA, 1-pb, 6) 1217 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].kex/1000, kex/1000, 2)
1218 1219
1220 - def x_test_bmrb_sub_cpmg(self):
1221 """U{Task #7858: <https://gna.org/task/?7858>} Make it possible to submit CPMG experiments for BMRB. 1222 This uses CPMG data from: 1223 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE. 1224 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 1225 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, DOI 10.1002/prot.22886 1226 """ 1227 1228 # Define path to data 1229 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 1230 1231 # Read data. 1232 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 1233 1234 # Set element 1235 self.interpreter.spin.element(element='N', spin_id=':*@N', force=False) 1236 #self.interpreter.spin.isotope(isotope='15N', spin_id=':*@N', force=False) 1237 # Rename molecule from None to 'HEWL' 1238 self.interpreter.molecule.name(mol_id=None, name='HEWL', force=True) 1239 self.interpreter.molecule.type(mol_id='#HEWL', type='protein', force=False) 1240 1241 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1242 print(spin_id) 1243 if resn == 'C': 1244 print(resi, resn) 1245 1246 # Select the thiol state of the system. 1247 # 'all disulfide bound', 'all free', 'all other bound', 'disulfide and other bound', 'free and disulfide bound', 'free and other bound', 'free disulfide and other bound', 'not available', 'not present', 'not reported', 'unknown' 1248 self.interpreter.bmrb.thiol_state(state='not reported') 1249 1250 # relax_data.temp_calibration(ri_id=None, method=None) 1251 1252 # Call display of bmrb. 1253 self.interpreter.bmrb.display()
1254 1255
1257 """U{Bug #21081<https://gna.org/bugs/?21081>} catch, the failure of a cluster analysis when spins are deselected.""" 1258 1259 # Clear the data store. 1260 self.interpreter.reset() 1261 1262 # Load the state. 1263 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21081_disp_cluster_fail.bz2' 1264 self.interpreter.state.load(state, force=True) 1265 1266 # Model selection - to catch the failure. 1267 self.interpreter.model_selection(method='AIC', modsel_pipe='final', bundle='relax_disp', pipes=['No Rex', 'CR72'])
1268 1269
1271 """U{Bug #21460<https://gna.org/bugs/?21460>} catch, the failure due to a spectrometer frequency having no relaxation data.""" 1272 1273 # Clear the data store. 1274 self.interpreter.reset() 1275 1276 # Load the state. 1277 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'saved_states'+sep+'bug_21460_bad_fields.bz2' 1278 self.interpreter.state.load(state, force=True) 1279 1280 # Execute the auto-analysis (fast). 1281 relax_disp.Relax_disp.opt_func_tol = 1e-5 1282 relax_disp.Relax_disp.opt_max_iterations = 1000 1283 relax_disp.Relax_disp(pipe_name="origin - relax_disp (Thu Jan 2 13:46:44 2014)", pipe_bundle="relax_disp (Thu Jan 2 13:46:44 2014)", results_dir=self.tmpdir, models=['R2eff', 'No Rex', 'CR72', 'NS CPMG 2-site expanded'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1284 1285
1287 """U{Bug #21665<https://gna.org/bugs/?21344>} catch, the failure of an analysis of a sparse acquired R1rho dataset with missing combinations of time and spin-lock field strengths using auto_analysis.""" 1288 1289 # Clear the data store. 1290 self.interpreter.reset() 1291 1292 # Load the state. 1293 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 1294 self.interpreter.state.load(state, force=True) 1295 1296 # Execute the auto-analysis (fast). 1297 relax_disp.Relax_disp.opt_func_tol = 1e-5 1298 relax_disp.Relax_disp.opt_max_iterations = 1000 1299 relax_disp.Relax_disp(pipe_name='base pipe', pipe_bundle='relax_disp', results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1300 1301
1303 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times, using minimise.calculate().""" 1304 1305 # Clear the data store. 1306 self.interpreter.reset() 1307 1308 # Load the state. 1309 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1310 self.interpreter.state.load(state, force=True) 1311 1312 # Run the calculation. 1313 self.interpreter.minimise.calculate(verbosity=1)
1314 1315
1317 """U{Bug #21665<https://gna.org/bugs/?21665>} catch, the failure due to a a CPMG analysis recorded at two fields at two delay times using auto_analysis.""" 1318 1319 # Clear the data store. 1320 self.interpreter.reset() 1321 1322 # Load the state. 1323 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21665.bz2' 1324 self.interpreter.state.load(state, force=True) 1325 1326 # Execute the auto-analysis (fast). 1327 relax_disp.Relax_disp.opt_func_tol = 1e-5 1328 relax_disp.Relax_disp.opt_max_iterations = 1000 1329 relax_disp.Relax_disp(pipe_name="compare_128_FT_R2eff", pipe_bundle="cpmg_disp_sod1d90a", results_dir=self.tmpdir, models=['R2eff'], grid_inc=3, mc_sim_num=5, modsel='AIC', pre_run_dir=None, insignificance=1.0, numeric_only=False, mc_sim_all_models=False, eliminate=True)
1330 1331
1333 """Catch U{bug #21715<https://gna.org/bugs/?21715>}, the failure of a clustered auto-analysis due to an IndexError.""" 1334 1335 # Clear the data store. 1336 self.interpreter.reset() 1337 1338 # Load the state. 1339 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'state.bz2' 1340 self.interpreter.state.load(state, force=True) 1341 1342 # Execute the auto-analysis (fast). 1343 pre_run_dir = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21715_clustered_indexerror'+sep+'non_clustered' 1344 relax_disp.Relax_disp.opt_func_tol = 1e-5 1345 relax_disp.Relax_disp.opt_max_iterations = 1000 1346 relax_disp.Relax_disp(pipe_name='origin - relax_disp (Sun Feb 23 19:36:51 2014)', pipe_bundle='relax_disp (Sun Feb 23 19:36:51 2014)', results_dir=self.tmpdir, models=['R2eff', 'No Rex'], grid_inc=11, mc_sim_num=3, modsel='AIC', pre_run_dir=pre_run_dir, insignificance=1.0, numeric_only=True, mc_sim_all_models=False, eliminate=True)
1347 1348
1350 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered B14 full analysis.""" 1351 1352 # Base data setup. 1353 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='B14_full', model_analyse = MODEL_B14_FULL)
1354 1355
1357 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered CR72 full analysis.""" 1358 1359 # Base data setup. 1360 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='CR72_full', model_analyse = MODEL_CR72_FULL)
1361 1362
1364 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE 3D full analysis.""" 1365 1366 # Base data setup. 1367 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_3d_full', model_analyse = MODEL_NS_CPMG_2SITE_3D_FULL)
1368 1369
1371 """Catch U{bug #22146<https://gna.org/bugs/?22146>}, the failure of unpacking R2A and R2B, when performing a clustered NS CPMG 2SITE STAR full analysis.""" 1372 1373 # Base data setup. 1374 self.setup_bug_22146_unpacking_r2a_r2b_cluster(folder='ns_cpmg_2site_star_full', model_analyse = MODEL_NS_CPMG_2SITE_STAR_FULL, places = 4)
1375 1376
1378 """Catch U{bug #22146<https://gna.org/bugs/?22477>}, the failure of issuing: grace.write(x_data_type='res_num', y_data_type=param) for a mixed CPMG analysis.""" 1379 1380 # Clear the data store. 1381 self.interpreter.reset() 1382 1383 # Load the state. 1384 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_22477_grace_write_k_AB_mixed_analysis'+sep+'bug_22477_results.bz2' 1385 self.interpreter.state.load(state, force=True) 1386 1387 param = 'k_AB' 1388 1389 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1390 print(spin_id, spin.params) 1391 if param in spin.params: 1392 print(spin_id, spin.k_AB, spin.k_AB_err) 1393 1394 # Perform write. 1395 self.interpreter.grace.write(x_data_type='res_num', y_data_type=param, file='%s.agr'%param, dir=self.tmpdir, force=True) 1396 1397 1398 # Test the header of the value.write parameter r2. 1399 param = 'r2' 1400 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1401 1402 file = open(self.tmpdir+sep+'%s.out'%param) 1403 lines = file.readlines() 1404 file.close() 1405 1406 for i, line in enumerate(lines): 1407 # Make the string test 1408 line_split = line.split() 1409 print(line_split) 1410 1411 if len(line_split) > 1: 1412 # Break at parameter header. 1413 if line_split[0] == "#" and line_split[1] == 'mol_name': 1414 nr_split_header = len(line_split) 1415 nr_split_header_i = i 1416 break 1417 1418 # Call the line after. 1419 line_split_val = lines[nr_split_header_i + 1].split() 1420 print(line_split_val) 1421 1422 # Assert that the number of columns is equal, plus 1 for "#". 1423 self.assertEqual(nr_split_header, len(line_split_val) + 1) 1424 1425 # Test the header of the value.write for parameter r2eff. 1426 param = 'r2eff' 1427 self.interpreter.value.write(param=param, file='%s.out'%param, dir=self.tmpdir, force=True) 1428 1429 file = open(self.tmpdir+sep+'%s.out'%param) 1430 lines = file.readlines() 1431 file.close() 1432 1433 for i, line in enumerate(lines): 1434 # Make the string test 1435 line_split = line.split() 1436 print(line_split) 1437 1438 if len(line_split) > 1: 1439 # Break at parameter header. 1440 if line_split[0] == "#" and line_split[1] == 'mol_name': 1441 nr_split_header = len(line_split) 1442 nr_split_header_i = i 1443 break 1444 1445 # Call the line after. 1446 line_split_val = lines[nr_split_header_i + 1].split() 1447 print(line_split_val) 1448 1449 # Assert that the number of columns is equal, plus 1 for "#". 1450 self.assertEqual(nr_split_header, len(line_split_val) + 1)
1451 1452
1454 """Catch U{bug #23186<https://gna.org/bugs/?23186>}: Error calculation of individual parameter "dw" from Monte-Carlo, is based on first spin.""" 1455 1456 # Clear the data store. 1457 self.interpreter.reset() 1458 1459 # Load the state. 1460 state = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_23186.bz2' 1461 self.interpreter.state.load(state, force=True) 1462 1463 # Dic key to spectrometer frq. 1464 dickey = 'SQ CPMG - 599.89086220 MHz' 1465 1466 # First get the resi 0 array of sim r2a. 1467 resi_0_r2a = [] 1468 1469 # Assign spins 1470 res0 = cdp.mol[0].res[0].spin[0] 1471 res1 = cdp.mol[0].res[1].spin[0] 1472 1473 print("Chi2 before call to minimise: %3.3f"%res0.chi2) 1474 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000, verbosity=0) 1475 print("Chi2 after call to minimise: %3.3f"%res0.chi2) 1476 1477 # Loop over the dics in spin. 1478 for cdic in res0.r2a_sim: 1479 resi_0_r2a.append(cdic[dickey]) 1480 1481 # Get stats with numpy 1482 resi_0_r2a_std = std(asarray(resi_0_r2a), ddof=1) 1483 1484 # First get the resi 86 array of sim r2a. 1485 resi_86_r2a = [] 1486 1487 # Loop over the dics in spin. 1488 for cdic in res1.r2a_sim: 1489 resi_86_r2a.append(cdic[dickey]) 1490 1491 # Get stats with numpy 1492 resi_86_r2a_std = std(asarray(resi_86_r2a), ddof=1) 1493 1494 # Then get for dw. 1495 1496 # First get the array of sim dw. 1497 resi_0_dw = res0.dw_sim 1498 resi_86_dw = res1.dw_sim 1499 1500 # Get stats with numpy 1501 resi_0_dw_std = std(asarray(resi_0_dw), ddof=1) 1502 resi_86_dw_std = std(asarray(resi_86_dw), ddof=1) 1503 1504 # Then get for spin independent parameter. 1505 1506 # First get the array of sim dw. 1507 resi_0_kAB = res0.k_AB_sim 1508 resi_86_kAB = res1.k_AB_sim 1509 1510 # Get stats with numpy 1511 resi_0_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1512 resi_86_kAB_std = std(asarray(resi_0_kAB), ddof=1) 1513 1514 # Assume they both std of k_AB values are equal 1515 self.assertEqual(resi_0_kAB_std, resi_86_kAB_std) 1516 1517 # Perform error analysis. 1518 self.interpreter.monte_carlo.error_analysis() 1519 1520 # Check values for k_AB. 1521 self.assertAlmostEqual(resi_0_kAB_std, res0.k_AB_err) 1522 self.assertAlmostEqual(resi_86_kAB_std, res1.k_AB_err) 1523 1524 # Check values for r2a. 1525 self.assertAlmostEqual(resi_0_r2a_std, res0.r2a_err[dickey]) 1526 self.assertAlmostEqual(resi_86_r2a_std, res1.r2a_err[dickey]) 1527 1528 # Check values for dw. 1529 self.assertAlmostEqual(resi_0_dw_std, res0.dw_err) 1530 self.assertAlmostEqual(resi_86_dw_std, res1.dw_err) 1531 1532 # The following is for Bug #23619: (https://gna.org/bugs/index.php?23619): Stored chi2 sim values from Monte-Carlo simulations does not equal normal chi2 values. 1533 # This is to show that this bug is invalid. The "very" different chi2 values stems from r2eff points being back-calculated values rather than original measured values. 1534 1535 # Check calculates the same Monte-Carlo chi2 values 1536 self.interpreter.monte_carlo.setup(number=3) 1537 self.interpreter.monte_carlo.create_data(method='back_calc') 1538 self.interpreter.monte_carlo.initial_values() 1539 1540 # Assign original data instead of back_calculated error. 1541 res0.r2eff_sim[0] = copy.copy(res0.r2eff) 1542 res0.r2eff_sim[1] = copy.copy(res0.r2eff) 1543 res0.r2eff_sim[2] = copy.copy(res0.r2eff) 1544 res1.r2eff_sim[0] = copy.copy(res1.r2eff) 1545 res1.r2eff_sim[1] = copy.copy(res1.r2eff) 1546 res1.r2eff_sim[2] = copy.copy(res1.r2eff) 1547 1548 self.interpreter.minimise.execute(min_algor='simplex', max_iter=100000) 1549 self.interpreter.monte_carlo.error_analysis() 1550 1551 # Get the simulation array and calculate the average 1552 spin_chi2_mc = res0.chi2 1553 spin_chi2_mc_sim = res0.chi2_sim 1554 spin_chi2_mc_sim_ave = average(spin_chi2_mc_sim) 1555 1556 print("The chi2 from calculation is: %3.3f"%spin_chi2_mc) 1557 print("The array with monte-carlo chi2 values is: %s"%spin_chi2_mc_sim) 1558 print("The average of this array is: %3.3f"%spin_chi2_mc_sim_ave) 1559 1560 self.assertAlmostEqual(spin_chi2_mc, spin_chi2_mc_sim_ave, 7)
1561 1562
1564 """Catch U{bug #9999<https://gna.org/bugs/?9999>}, The slow optimisation of R1rho R2eff error estimation with Monte Carlo simulations.""" 1565 1566 # Define path to data 1567 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 1568 1569 # Read data. 1570 self.interpreter.results.read(prev_data_path + sep + 'results') 1571 1572 # Now count number 1573 graph_nr = 1 1574 for exp_type, frq, offset, point in loop_exp_frq_offset_point(return_indices=False): 1575 print("\nGraph nr %i" % graph_nr) 1576 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 1577 print(exp_type, frq, offset, point, time) 1578 graph_nr += 1 1579 1580 ## Possibly do an error analysis. 1581 1582 # Check if intensity errors have already been calculated by the user. 1583 precalc = True 1584 for spin in spin_loop(skip_desel=True): 1585 # No structure. 1586 if not hasattr(spin, 'peak_intensity_err'): 1587 precalc = False 1588 break 1589 1590 # Determine if a spectrum ID is missing from the list. 1591 for id in cdp.spectrum_ids: 1592 if id not in spin.peak_intensity_err: 1593 precalc = False 1594 break 1595 1596 # Skip. 1597 if precalc: 1598 print("Skipping the error analysis as it has already been performed.") 1599 1600 else: 1601 # Loop over the spectrometer frequencies. 1602 for frq in loop_frq(): 1603 # Generate a list of spectrum IDs matching the frequency. 1604 ids = [] 1605 for id in cdp.spectrum_ids: 1606 # Check that the spectrometer frequency matches. 1607 match_frq = True 1608 if frq != None and cdp.spectrometer_frq[id] != frq: 1609 match_frq = False 1610 1611 # Add the ID. 1612 if match_frq: 1613 ids.append(id) 1614 1615 # Run the error analysis on the subset. 1616 self.interpreter.spectrum.error_analysis(subset=ids) 1617 1618 print("has_exponential_exp_type:", has_exponential_exp_type()) 1619 1620 model = 'R2eff' 1621 self.interpreter.relax_disp.select_model(model) 1622 1623 for spin, spin_id in spin_loop(return_id=True, skip_desel=True): 1624 #delattr(spin, 'r2eff') 1625 #delattr(spin, 'r2eff_err') 1626 #delattr(spin, 'i0') 1627 #delattr(spin, 'i0_err') 1628 setattr(spin, 'r2eff', {}) 1629 setattr(spin, 'r2eff_err', {}) 1630 setattr(spin, 'i0', {}) 1631 setattr(spin, 'i0_err', {}) 1632 1633 # Do Grid Search 1634 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=21, constraints=True, verbosity=1) 1635 1636 # Start dic. 1637 my_dic = {} 1638 1639 # Define counter for maximum elements in the numpy array list 1640 NE = 0 1641 NS = 1 1642 NM = 0 1643 NO = 0 1644 ND = 0 1645 NT = 0 1646 1647 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1648 # Save to counter. 1649 if ei > NE: 1650 NE = ei 1651 if mi > NM: 1652 NM = mi 1653 if oi > NO: 1654 NO = oi 1655 if di > ND: 1656 ND = di 1657 1658 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1659 # Save to counter. 1660 if ti > NT: 1661 NT = ti 1662 1663 # Add 1 to counter, since index start from 0. 1664 NE = NE + 1 1665 NM = NM + 1 1666 NO = NO + 1 1667 ND = ND + 1 1668 NT = NT + 1 1669 1670 # Make data array. 1671 values_arr = zeros([NE, NS, NM, NO, ND, NT]) 1672 errors_arr = zeros([NE, NS, NM, NO, ND, NT]) 1673 times_arr = zeros([NE, NS, NM, NO, ND, NT]) 1674 struct_arr = zeros([NE, NS, NM, NO, ND, NT]) 1675 param_key_list = [] 1676 1677 1678 # Loop over each spectrometer frequency and dispersion point. 1679 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1680 # Add key to dic. 1681 my_dic[spin_id] = {} 1682 1683 # Generate spin string. 1684 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1685 1686 # Loop over the parameters. 1687 #print("Grid optimised parameters for spin: %s" % (spin_string)) 1688 1689 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1690 # Generate the param_key. 1691 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1692 1693 # Append key. 1694 param_key_list.append(param_key) 1695 1696 # Add key to dic. 1697 my_dic[spin_id][param_key] = {} 1698 1699 # Get the value. 1700 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1701 i0_value = getattr(cur_spin, 'i0')[param_key] 1702 1703 # Save to dic. 1704 my_dic[spin_id][param_key]['R2eff_value_grid'] = R2eff_value 1705 my_dic[spin_id][param_key]['i0_value_grid'] = i0_value 1706 1707 ## Now try do a line of best fit by least squares. 1708 # The peak intensities, errors and times. 1709 values = [] 1710 errors = [] 1711 times = [] 1712 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1713 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1714 values.append(value) 1715 1716 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1717 errors.append(error) 1718 times.append(time) 1719 1720 # Save to numpy arrays. 1721 values_arr[ei, 0, mi, oi, di, ti] = value 1722 errors_arr[ei, 0, mi, oi, di, ti] = error 1723 times_arr[ei, 0, mi, oi, di, ti] = time 1724 struct_arr[ei, 0, mi, oi, di, ti] = 1.0 1725 1726 # y= A exp(x * k) 1727 # w[i] = ln(y[i]) 1728 # int[i] = i0 * exp( - times[i] * r2eff); 1729 w = log(array(values)) 1730 x = - array(times) 1731 n = len(times) 1732 1733 b = (sum(x*w) - 1./n * sum(x) * sum(w) ) / ( sum(x**2) - 1./n * (sum(x))**2 ) 1734 a = 1./n * sum(w) - b * 1./n * sum(x) 1735 R2eff_est = b 1736 i0_est = exp(a) 1737 1738 my_dic[spin_id][param_key]['R2eff_est'] = R2eff_est 1739 my_dic[spin_id][param_key]['i0_est'] = i0_est 1740 1741 # Print value. 1742 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1743 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1744 1745 1746 # Do minimisation. 1747 set_func_tol = 1e-25 1748 set_max_iter = int(1e7) 1749 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 1750 1751 # Loop over each spectrometer frequency and dispersion point. 1752 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1753 # Generate spin string. 1754 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1755 1756 # Loop over the parameters. 1757 print("Optimised parameters for spin: %s" % (spin_string)) 1758 1759 for exp_type, frq, offset, point in loop_exp_frq_offset_point(): 1760 # Generate the param_key. 1761 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1762 1763 # Get the value. 1764 R2eff_value = getattr(cur_spin, 'r2eff')[param_key] 1765 i0_value = getattr(cur_spin, 'i0')[param_key] 1766 1767 # Extract from dic. 1768 R2eff_value_grid = my_dic[spin_id][param_key]['R2eff_value_grid'] 1769 i0_value_grid = my_dic[spin_id][param_key]['i0_value_grid'] 1770 R2eff_est = my_dic[spin_id][param_key]['R2eff_est'] 1771 i0_est = my_dic[spin_id][param_key]['i0_est'] 1772 1773 # Print value. 1774 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'R2eff', "Value : Estimated:", R2eff_value, R2eff_est)) 1775 #print("%-10s %-6s %-6s %3.1f : %3.1f" % ("Parameter:", 'i0', "Value: Estimated:", i0_value, i0_est)) 1776 1777 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'R2eff', "Grid : Min : Estimated:", R2eff_value_grid, R2eff_value, R2eff_est)) 1778 print("%-10s %-6s %-6s %3.1f : %3.1f: %3.1f" % ("Parameter:", 'i0', "Grid : Min : Estimated:", i0_value_grid, i0_value, i0_est)) 1779 1780 print(NE, NS, NM, NO, ND, NT) 1781 for param_key in param_key_list: 1782 print(" '%s'," % param_key) 1783 print(values_arr.shape) 1784 1785 # Save arrays to profiling. 1786 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'curve_fitting'+sep+'profiling'+sep
1787 #save(data_path + "values_arr", values_arr) 1788 #save(data_path + "errors_arr", errors_arr) 1789 #save(data_path + "times_arr", times_arr) 1790 #save(data_path + "struct_arr", struct_arr) 1791 1792
1793 - def test_bug_atul_srivastava(self):
1794 """Test data from Atul Srivastava. This is a bug missing raising a Relax Error, since the setup points to a situation where the data 1795 shows it is exponential fitting, but only one time point is added per file. 1796 1797 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1718>}: 1798 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735>}: 1799 This follows: U{Thread <http://thread.gmane.org/gmane.science.nmr.relax.user/1735/focus=1736>}: 1800 1801 """ 1802 1803 # Data path. 1804 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_Atul_Srivastava' 1805 file = data_path + sep + 'bug_script.py' 1806 1807 # Run script. 1808 self.interpreter.script(file=file, dir=None) 1809 1810 # The grid search size (the number of increments per dimension). 1811 GRID_INC = 11 1812 1813 # Check-data. 1814 ################# 1815 1816 # Loop over spins, to see current setup. 1817 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1818 print(mol_name, resi, resn, spin_id) 1819 1820 # Loop over setup. 1821 for id in cdp.exp_type: 1822 print(id, cdp.exp_type[id], cdp.spectrometer_frq[id], cdp.spin_lock_offset[id], cdp.spin_lock_nu1[id]) 1823 1824 1825 # Manual minimisation. 1826 ################# 1827 if True: 1828 # Set the model. 1829 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 1830 1831 # Check if intensity errors have already been calculated. 1832 check_intensity_errors() 1833 1834 # Calculate the R2eff values for the fixed relaxation time period data types. 1835 if cdp.model_type == MODEL_R2EFF and not has_exponential_exp_type(): 1836 self.interpreter.minimise.calculate() 1837 1838 # Optimise the model. 1839 else: 1840 constraints = False 1841 min_algor = 'Newton' 1842 self.assertRaises(RelaxError, self.interpreter.minimise.grid_search, inc=GRID_INC) 1843 self.assertRaises(RelaxError, self.interpreter.minimise.execute, min_algor=min_algor, constraints=constraints) 1844 1845 # Inspect. 1846 if False: 1847 # Loop over attributes. 1848 par_attr_list = ['r2eff', 'i0'] 1849 1850 # Collect the estimation data. 1851 my_dic = {} 1852 param_key_list = [] 1853 est_keys = [] 1854 est_key = 'grid' 1855 est_keys.append(est_key) 1856 spin_id_list = [] 1857 1858 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 1859 # Add key to dic. 1860 my_dic[spin_id] = {} 1861 1862 # Add key for estimate. 1863 my_dic[spin_id][est_key] = {} 1864 1865 # Add spin key to list. 1866 spin_id_list.append(spin_id) 1867 1868 # Generate spin string. 1869 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 1870 1871 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 1872 # Generate the param_key. 1873 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 1874 #param_key = generate_r20_key(exp_type=exp_type, frq=frq) 1875 1876 # Append key. 1877 param_key_list.append(param_key) 1878 1879 # Add key to dic. 1880 my_dic[spin_id][est_key][param_key] = {} 1881 1882 # Get the value. 1883 # Loop over err attributes. 1884 for par_attr in par_attr_list: 1885 if hasattr(cur_spin, par_attr): 1886 get_par_attr = getattr(cur_spin, par_attr)[param_key] 1887 else: 1888 get_par_attr = 0.0 1889 1890 # Save to dic. 1891 my_dic[spin_id][est_key][param_key][par_attr] = get_par_attr 1892 1893 # Check number of values. 1894 values = [] 1895 errors = [] 1896 times = [] 1897 for time, ti in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point, return_indices=True): 1898 value = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, sim_index=None) 1899 values.append(value) 1900 1901 error = average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True) 1902 errors.append(error) 1903 times.append(time) 1904 1905 # Save to dic. 1906 my_dic[spin_id][est_key][param_key]['values'] = values 1907 my_dic[spin_id][est_key][param_key]['errors'] = errors 1908 my_dic[spin_id][est_key][param_key]['times'] = times 1909 1910 # Analysis variables. 1911 ##################### 1912 1913 # The dispersion models. 1914 MODELS = ['R2eff', 'No Rex'] 1915 1916 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 1917 MC_NUM = 10 1918 1919 # A flag which if True will activate Monte Carlo simulations for all models. Note this will hugely increase the computation time. 1920 MC_SIM_ALL_MODELS = False 1921 1922 # The results directory. 1923 RESULTS_DIR = ds.tmpdir 1924 1925 # The directory of results of an earlier analysis without clustering. 1926 PRE_RUN_DIR = None 1927 1928 # The model selection technique to use. 1929 MODSEL = 'AIC' 1930 1931 # The flag for only using numeric models in the final model selection. 1932 NUMERIC_ONLY = False 1933 1934 # The R1rho value in rad/s by which to judge insignificance. If the maximum difference between two points on all dispersion curves for a spin is less than this value, that spin will be deselected. 1935 INSIGNIFICANCE = 1.0 1936 1937 # Auto-analysis execution. 1938 self.assertRaises(RelaxError, relax_disp.Relax_disp, pipe_name='relax_disp', results_dir=RESULTS_DIR, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, insignificance=INSIGNIFICANCE, numeric_only=NUMERIC_ONLY)
1939 1940
1942 """Test data, where peak intensities are negative in CPMG 1943 1944 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 1945 """ 1946 1947 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'bug_neg_int_acbp_cpmg_disp_048MGuHCl_40C_041223' 1948 1949 # Create the spins 1950 self.interpreter.spectrum.read_spins(file="peaks_list_max_standard.ser", dir=data_path) 1951 1952 # Name the isotope for field strength scaling. 1953 self.interpreter.spin.isotope(isotope='15N') 1954 1955 # Read the spectrum from NMRSeriesTab file. The "auto" will generate spectrum name of form: Z_A{i} 1956 self.interpreter.spectrum.read_intensities(file="peaks_list_max_standard.ser", dir=data_path, spectrum_id='auto', int_method='height') 1957 1958 # Loop over the spectra settings. 1959 ncycfile=open(data_path + sep + 'ncyc.txt', 'r') 1960 1961 # Make empty ncyclist 1962 ncyclist = [] 1963 1964 i = 0 1965 for line in ncycfile: 1966 ncyc = line.split()[0] 1967 time_T2 = float(line.split()[1]) 1968 vcpmg = line.split()[2] 1969 set_sfrq = float(line.split()[3]) 1970 rmsd_err = float(line.split()[4]) 1971 1972 # Test if spectrum is a reference 1973 if float(vcpmg) == 0.0: 1974 vcpmg = None 1975 else: 1976 vcpmg = round(float(vcpmg), 3) 1977 1978 # Add ncyc to list 1979 ncyclist.append(int(ncyc)) 1980 1981 # Set the current spectrum id 1982 current_id = "Z_A%s"%(i) 1983 1984 # Set the current experiment type. 1985 self.interpreter.relax_disp.exp_type(spectrum_id=current_id, exp_type='SQ CPMG') 1986 1987 # Set the peak intensity errors, as defined as the baseplane RMSD. 1988 self.interpreter.spectrum.baseplane_rmsd(error=rmsd_err, spectrum_id=current_id) 1989 1990 # Set the NMR field strength of the spectrum. 1991 self.interpreter.spectrometer.frequency(id=current_id, frq=set_sfrq, units='MHz') 1992 1993 # Relaxation dispersion CPMG constant time delay T (in s). 1994 self.interpreter.relax_disp.relax_time(spectrum_id=current_id, time=time_T2) 1995 1996 # Set the relaxation dispersion CPMG frequencies. 1997 self.interpreter.relax_disp.cpmg_setup(spectrum_id=current_id, cpmg_frq=vcpmg) 1998 1999 i += 1 2000 2001 # Specify the duplicated spectra. 2002 self.interpreter.spectrum.replicated(spectrum_ids=['Z_A1', 'Z_A15']) 2003 2004 # Delete replicate spectrum 2005 #self.interpreter.spectrum.delete('Z_A15') 2006 2007 MODELS = [MODEL_R2EFF, MODEL_NOREX] 2008 GRID_INC = 5; MC_NUM = 3; MODSEL = 'AIC' 2009 2010 results_dir = ds.tmpdir 2011 2012 # Execute 2013 relax_disp.Relax_disp(pipe_name='relax_disp', results_dir=results_dir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 2014 2015 # Check spin less R2eff points. 2016 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 2017 # Assert that spin 4, has one less R2eff point, since one of the intensities are negative. 2018 if spin_id == ':4@N': 2019 self.assertEqual(len(cur_spin.r2eff), 14) 2020 else: 2021 self.assertEqual(len(cur_spin.r2eff), 15)
2022 2023
2024 - def test_check_missing_r1(self):
2025 """Test of the check_missing_r1() function.""" 2026 2027 # Set up some spins. 2028 self.setup_missing_r1_spins() 2029 2030 # Set variables. 2031 exp_type = 'R1rho' 2032 frq = 800.1 * 1E6 2033 2034 spectrum_id='test' 2035 2036 # Set an experiment type to the pipe. 2037 self.interpreter.relax_disp.exp_type(spectrum_id=spectrum_id, exp_type=exp_type) 2038 2039 # Set a frequency to loop through. 2040 self.interpreter.spectrometer.frequency(id=spectrum_id, frq=frq, units='Hz') 2041 2042 # Check R1 for DPL94. 2043 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2044 self.assertEqual(check_missing_r1_return, True) 2045 2046 # Check R1 for R2eff. 2047 check_missing_r1_return = check_missing_r1(model=MODEL_R2EFF) 2048 self.assertEqual(check_missing_r1_return, False) 2049 2050 # The path to the data files. 2051 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 2052 2053 # Now load some R1 data. 2054 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 2055 2056 # Check R1. 2057 check_missing_r1_return = check_missing_r1(model=MODEL_DPL94) 2058 self.assertEqual(check_missing_r1_return, False)
2059 2060
2062 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site 3D, for clustered analysis. 2063 2064 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2065 2066 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2067 """ 2068 2069 # Reset. 2070 #self.interpreter.reset() 2071 2072 ## Set Experiments. 2073 model_create = 'B14' 2074 #model_create = 'NS CPMG 2-site expanded' 2075 model_analyse = 'NS CPMG 2-site 3D' 2076 2077 # Exp 1 2078 sfrq_1 = 599.8908617*1E6 2079 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2080 time_T2_1 = 0.06 2081 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2082 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2083 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2084 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2085 2086 sfrq_2 = 499.8908617*1E6 2087 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2088 time_T2_2 = 0.05 2089 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2090 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2091 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2092 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2093 2094 # Collect all exps 2095 exps = [exp_1, exp_2] 2096 2097 spins = [ 2098 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2099 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2100 ] 2101 2102 # Collect the data to be used. 2103 ds.data = [model_create, model_analyse, spins, exps] 2104 2105 # The tmp directory. None is the local directory. 2106 ds.tmpdir = ds.tmpdir 2107 2108 # The results directory. None is the local directory. 2109 #ds.resdir = None 2110 ds.resdir = ds.tmpdir 2111 2112 # Do r20_from_min_r2eff ?. 2113 ds.r20_from_min_r2eff = True 2114 2115 # Remove insignificant level. 2116 ds.insignificance = 0.0 2117 2118 # The grid search size (the number of increments per dimension). 2119 ds.GRID_INC = None 2120 2121 # The do clustering. 2122 ds.do_cluster = True 2123 2124 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2125 # The default value is 1e-25. 2126 ds.set_func_tol = 1e-1 2127 2128 # The maximum number of iterations. 2129 # The default value is 1e7. 2130 ds.set_max_iter = 1000 2131 2132 # The verbosity level. 2133 ds.verbosity = 1 2134 2135 # The rel_change WARNING level. 2136 ds.rel_change = 0.05 2137 2138 # The plot_curves. 2139 ds.plot_curves = False 2140 2141 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2142 ds.sherekhan_input = False 2143 2144 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2145 ds.opendx = False 2146 2147 # The set r2eff err. 2148 ds.r2eff_err = 0.1 2149 2150 # The print result info. 2151 ds.print_res = True 2152 2153 # Execute the script. 2154 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2155 2156 cur_spins = ds.data[2] 2157 # Compare results. 2158 for i in range(len(cur_spins)): 2159 res_name, res_num, spin_name, params = cur_spins[i] 2160 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2161 cur_spin = return_spin(cur_spin_id) 2162 2163 grid_params = ds.grid_results[i][3] 2164 2165 # Extract the clust results. 2166 min_params = ds.clust_results[i][3] 2167 # Now read the parameters. 2168 print("For spin: '%s'"%cur_spin_id) 2169 for mo_param in cur_spin.params: 2170 # The R2 is a dictionary, depending on spectrometer frequency. 2171 if isinstance(getattr(cur_spin, mo_param), dict): 2172 grid_r2 = grid_params[mo_param] 2173 min_r2 = min_params[mo_param] 2174 set_r2 = params[mo_param] 2175 for key, val in list(set_r2.items()): 2176 grid_r2_frq = grid_r2[key] 2177 min_r2_frq = min_r2[key] 2178 set_r2_frq = set_r2[key] 2179 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2180 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2181 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2182 if rel_change > ds.rel_change: 2183 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2184 print("###################################") 2185 2186 ## Make test on R2. 2187 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2188 else: 2189 grid_val = grid_params[mo_param] 2190 min_val = min_params[mo_param] 2191 set_val = params[mo_param] 2192 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2193 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2194 if rel_change > ds.rel_change: 2195 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2196 print("###################################") 2197 2198 ## Make test on parameters. 2199 if mo_param == 'dw': 2200 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2201 elif mo_param == 'kex': 2202 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2203 elif mo_param == 'pA': 2204 self.assertAlmostEqual(set_val, min_val, 2)
2205 2206
2208 """Test synthetic cpmg data. Created with B14, analysed with NS CPMG 2site STAR, for clustered analysis. 2209 2210 This is part of: U{Task #7807 <https://gna.org/task/index.php?7807>}: Speed-up of dispersion models for Clustered analysis. 2211 2212 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2213 """ 2214 2215 # Reset. 2216 #self.interpreter.reset() 2217 2218 ## Set Experiments. 2219 model_create = 'B14' 2220 #model_create = 'NS CPMG 2-site expanded' 2221 model_analyse = 'NS CPMG 2-site star' 2222 2223 # Exp 1 2224 sfrq_1 = 599.8908617*1E6 2225 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2226 time_T2_1 = 0.06 2227 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2228 #r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2229 r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2230 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2231 2232 sfrq_2 = 499.8908617*1E6 2233 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2234 time_T2_2 = 0.05 2235 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2236 #r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2237 r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2238 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2239 2240 # Collect all exps 2241 exps = [exp_1, exp_2] 2242 2243 spins = [ 2244 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.95, 'dw': 2.} ], 2245 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.95, 'dw': 1.} ] 2246 ] 2247 2248 # Collect the data to be used. 2249 ds.data = [model_create, model_analyse, spins, exps] 2250 2251 # The tmp directory. None is the local directory. 2252 ds.tmpdir = ds.tmpdir 2253 2254 # The results directory. None is the local directory. 2255 #ds.resdir = None 2256 ds.resdir = ds.tmpdir 2257 2258 # Do r20_from_min_r2eff ?. 2259 ds.r20_from_min_r2eff = True 2260 2261 # Remove insignificant level. 2262 ds.insignificance = 0.0 2263 2264 # The grid search size (the number of increments per dimension). 2265 ds.GRID_INC = None 2266 2267 # The do clustering. 2268 ds.do_cluster = True 2269 2270 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2271 # The default value is 1e-25. 2272 ds.set_func_tol = 1e-1 2273 2274 # The maximum number of iterations. 2275 # The default value is 1e7. 2276 ds.set_max_iter = 1000 2277 2278 # The verbosity level. 2279 ds.verbosity = 1 2280 2281 # The rel_change WARNING level. 2282 ds.rel_change = 0.05 2283 2284 # The plot_curves. 2285 ds.plot_curves = False 2286 2287 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2288 ds.sherekhan_input = False 2289 2290 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2291 ds.opendx = False 2292 2293 # The set r2eff err. 2294 ds.r2eff_err = 0.1 2295 2296 # The print result info. 2297 ds.print_res = True 2298 2299 # Execute the script. 2300 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2301 2302 cur_spins = ds.data[2] 2303 # Compare results. 2304 for i in range(len(cur_spins)): 2305 res_name, res_num, spin_name, params = cur_spins[i] 2306 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2307 cur_spin = return_spin(cur_spin_id) 2308 2309 grid_params = ds.grid_results[i][3] 2310 2311 # Extract the clust results. 2312 min_params = ds.clust_results[i][3] 2313 # Now read the parameters. 2314 print("For spin: '%s'"%cur_spin_id) 2315 for mo_param in cur_spin.params: 2316 # The R2 is a dictionary, depending on spectrometer frequency. 2317 if isinstance(getattr(cur_spin, mo_param), dict): 2318 grid_r2 = grid_params[mo_param] 2319 min_r2 = min_params[mo_param] 2320 set_r2 = params[mo_param] 2321 for key, val in list(set_r2.items()): 2322 grid_r2_frq = grid_r2[key] 2323 min_r2_frq = min_r2[key] 2324 set_r2_frq = set_r2[key] 2325 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2326 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2327 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2328 if rel_change > ds.rel_change: 2329 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2330 print("###################################") 2331 2332 ## Make test on R2. 2333 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2334 else: 2335 grid_val = grid_params[mo_param] 2336 min_val = min_params[mo_param] 2337 set_val = params[mo_param] 2338 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2339 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2340 if rel_change > ds.rel_change: 2341 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2342 print("###################################") 2343 2344 ## Make test on parameters. 2345 if mo_param == 'dw': 2346 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2347 elif mo_param == 'kex': 2348 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2349 elif mo_param == 'pA': 2350 self.assertAlmostEqual(set_val, min_val, 2)
2351 2352
2354 """Test synthetic cpmg data. 2355 2356 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with CR72. 2357 """ 2358 2359 # Reset. 2360 #self.interpreter.reset() 2361 2362 ## Set Experiments. 2363 model_create = 'NS CPMG 2-site 3D' 2364 #model_create = 'NS CPMG 2-site expanded' 2365 model_analyse = 'CR72' 2366 # Exp 1 2367 sfrq_1 = 599.8908617*1E6 2368 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2369 time_T2_1 = 0.06 2370 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2371 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2372 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2373 2374 sfrq_2 = 499.8908617*1E6 2375 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2376 time_T2_2 = 0.05 2377 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2378 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2379 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2380 2381 # Collect all exps 2382 exps = [exp_1, exp_2] 2383 2384 spins = [ 2385 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2386 ] 2387 2388 # Collect the data to be used. 2389 ds.data = [model_create, model_analyse, spins, exps] 2390 2391 # The tmp directory. None is the local directory. 2392 ds.tmpdir = ds.tmpdir 2393 2394 # The results directory. None is the local directory. 2395 #ds.resdir = None 2396 ds.resdir = ds.tmpdir 2397 2398 # Do r20_from_min_r2eff ?. 2399 ds.r20_from_min_r2eff = True 2400 2401 # Remove insignificant level. 2402 ds.insignificance = 0.0 2403 2404 # The grid search size (the number of increments per dimension). 2405 ds.GRID_INC = 8 2406 2407 # The do clustering. 2408 ds.do_cluster = False 2409 2410 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2411 # The default value is 1e-25. 2412 ds.set_func_tol = 1e-9 2413 2414 # The maximum number of iterations. 2415 # The default value is 1e7. 2416 ds.set_max_iter = 1000 2417 2418 # The verbosity level. 2419 ds.verbosity = 1 2420 2421 # The rel_change WARNING level. 2422 ds.rel_change = 0.05 2423 2424 # The plot_curves. 2425 ds.plot_curves = False 2426 2427 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2428 ds.sherekhan_input = False 2429 2430 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2431 ds.opendx = False 2432 2433 # The set r2eff err. 2434 ds.r2eff_err = 0.1 2435 2436 # The print result info. 2437 ds.print_res = False 2438 2439 # Execute the script. 2440 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2441 2442 cur_spins = ds.data[2] 2443 # Compare results. 2444 for i in range(len(cur_spins)): 2445 res_name, res_num, spin_name, params = cur_spins[i] 2446 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2447 cur_spin = return_spin(cur_spin_id) 2448 2449 grid_params = ds.grid_results[i][3] 2450 min_params = ds.min_results[i][3] 2451 # Now read the parameters. 2452 print("For spin: '%s'"%cur_spin_id) 2453 for mo_param in cur_spin.params: 2454 # The R2 is a dictionary, depending on spectrometer frequency. 2455 if isinstance(getattr(cur_spin, mo_param), dict): 2456 grid_r2 = grid_params[mo_param] 2457 min_r2 = min_params[mo_param] 2458 set_r2 = params[mo_param] 2459 for key, val in list(set_r2.items()): 2460 grid_r2_frq = grid_r2[key] 2461 min_r2_frq = min_r2[key] 2462 set_r2_frq = set_r2[key] 2463 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2464 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2465 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2466 if rel_change > ds.rel_change: 2467 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2468 print("###################################") 2469 2470 ## Make test on R2. 2471 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2472 else: 2473 grid_val = grid_params[mo_param] 2474 min_val = min_params[mo_param] 2475 set_val = params[mo_param] 2476 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2477 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2478 if rel_change > ds.rel_change: 2479 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2480 print("###################################") 2481 2482 ## Make test on parameters. 2483 if mo_param == 'dw': 2484 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2485 elif mo_param == 'kex': 2486 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2487 elif mo_param == 'pA': 2488 self.assertAlmostEqual(set_val, min_val, 3)
2489 2490
2492 """Test synthetic cpmg data. 2493 2494 This script will produce synthetic CPMG R2eff values according to the NS CPMG 2-site 3D model, and the fit the data with B14. 2495 Try to catch bug #22021 U{https://gna.org/bugs/index.php?22021}: Model B14 shows bad fitting to data. 2496 """ 2497 2498 # Reset. 2499 #self.interpreter.reset() 2500 2501 ## Set Experiments. 2502 model_create = 'NS CPMG 2-site 3D' 2503 #model_create = 'NS CPMG 2-site expanded' 2504 model_analyse = 'B14' 2505 # Exp 1 2506 sfrq_1 = 599.8908617*1E6 2507 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2508 time_T2_1 = 0.06 2509 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2510 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2511 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2512 2513 sfrq_2 = 499.8908617*1E6 2514 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2515 time_T2_2 = 0.05 2516 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2517 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2518 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2519 2520 # Collect all exps 2521 exps = [exp_1, exp_2] 2522 2523 spins = [ 2524 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:10.}, 'r2a': {r20_key_1:10., r20_key_2:10.}, 'r2b': {r20_key_1:10., r20_key_2:10.}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ] 2525 ] 2526 2527 # Collect the data to be used. 2528 ds.data = [model_create, model_analyse, spins, exps] 2529 2530 # The tmp directory. None is the local directory. 2531 ds.tmpdir = ds.tmpdir 2532 2533 # The results directory. None is the local directory. 2534 #ds.resdir = None 2535 ds.resdir = ds.tmpdir 2536 2537 # Do r20_from_min_r2eff ?. 2538 ds.r20_from_min_r2eff = True 2539 2540 # Remove insignificant level. 2541 ds.insignificance = 0.0 2542 2543 # The grid search size (the number of increments per dimension). 2544 ds.GRID_INC = 8 2545 2546 # The do clustering. 2547 ds.do_cluster = False 2548 2549 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2550 # The default value is 1e-25. 2551 ds.set_func_tol = 1e-9 2552 2553 # The maximum number of iterations. 2554 # The default value is 1e7. 2555 ds.set_max_iter = 1000 2556 2557 # The verbosity level. 2558 ds.verbosity = 1 2559 2560 # The rel_change WARNING level. 2561 ds.rel_change = 0.05 2562 2563 # The plot_curves. 2564 ds.plot_curves = False 2565 2566 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2567 ds.sherekhan_input = False 2568 2569 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2570 ds.opendx = False 2571 2572 # The set r2eff err. 2573 ds.r2eff_err = 0.1 2574 2575 # The print result info. 2576 ds.print_res = False 2577 2578 # Execute the script. 2579 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2580 2581 cur_spins = ds.data[2] 2582 # Compare results. 2583 for i in range(len(cur_spins)): 2584 res_name, res_num, spin_name, params = cur_spins[i] 2585 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2586 cur_spin = return_spin(cur_spin_id) 2587 2588 grid_params = ds.grid_results[i][3] 2589 min_params = ds.min_results[i][3] 2590 # Now read the parameters. 2591 print("For spin: '%s'"%cur_spin_id) 2592 for mo_param in cur_spin.params: 2593 # The R2 is a dictionary, depending on spectrometer frequency. 2594 if isinstance(getattr(cur_spin, mo_param), dict): 2595 grid_r2 = grid_params[mo_param] 2596 min_r2 = min_params[mo_param] 2597 set_r2 = params[mo_param] 2598 for key, val in list(set_r2.items()): 2599 grid_r2_frq = grid_r2[key] 2600 min_r2_frq = min_r2[key] 2601 set_r2_frq = set_r2[key] 2602 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2603 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2604 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2605 if rel_change > ds.rel_change: 2606 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2607 print("###################################") 2608 2609 ## Make test on R2. 2610 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 2) 2611 else: 2612 grid_val = grid_params[mo_param] 2613 min_val = min_params[mo_param] 2614 set_val = params[mo_param] 2615 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2616 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2617 if rel_change > ds.rel_change: 2618 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2619 print("###################################") 2620 2621 ## Make test on parameters. 2622 if mo_param == 'dw': 2623 self.assertAlmostEqual(set_val/10, min_val/10, 5) 2624 elif mo_param == 'kex': 2625 self.assertAlmostEqual(set_val/1000, min_val/1000, 5) 2626 elif mo_param == 'pA': 2627 self.assertAlmostEqual(set_val, min_val, 6)
2628 2629
2631 """Test synthetic cpmg data. For CR72 with small noise and cluster. 2632 2633 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2634 """ 2635 2636 # Reset. 2637 #self.interpreter.reset() 2638 2639 ## Set Experiments. 2640 model_create = 'NS CPMG 2-site 3D' 2641 #model_create = 'NS CPMG 2-site expanded' 2642 model_analyse = 'CR72' 2643 2644 # Exp 1 2645 sfrq_1 = 599.8908617*1E6 2646 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2647 time_T2_1 = 0.06 2648 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2649 r2eff_errs_1 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2650 #r2eff_errs_1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2651 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_errs_1] 2652 2653 sfrq_2 = 499.8908617*1E6 2654 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2655 time_T2_2 = 0.05 2656 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2657 r2eff_errs_2 = [0.05, -0.05, 0.05, -0.05, 0.05, -0.05, 0.05, -0.05] 2658 #r2eff_errs_2 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 2659 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_errs_2] 2660 2661 # Collect all exps 2662 exps = [exp_1, exp_2] 2663 2664 spins = [ 2665 ['Ala', 1, 'N', {'r2': {r20_key_1:10., r20_key_2:11.5}, 'r2a': {r20_key_1:10., r20_key_2:11.5}, 'r2b': {r20_key_1:10., r20_key_2:11.5}, 'kex': 1000., 'pA': 0.99, 'dw': 2.} ], 2666 ['Ala', 2, 'N', {'r2': {r20_key_1:13., r20_key_2:14.5}, 'r2a': {r20_key_1:13., r20_key_2:14.5}, 'r2b': {r20_key_1:13., r20_key_2:14.5}, 'kex': 1000., 'pA': 0.99, 'dw': 1.} ] 2667 ] 2668 2669 # Collect the data to be used. 2670 ds.data = [model_create, model_analyse, spins, exps] 2671 2672 # The tmp directory. None is the local directory. 2673 ds.tmpdir = ds.tmpdir 2674 2675 # The results directory. None is the local directory. 2676 #ds.resdir = None 2677 ds.resdir = ds.tmpdir 2678 2679 # Do r20_from_min_r2eff ?. 2680 ds.r20_from_min_r2eff = True 2681 2682 # Remove insignificant level. 2683 ds.insignificance = 0.0 2684 2685 # The grid search size (the number of increments per dimension). 2686 ds.GRID_INC = 13 2687 2688 # The do clustering. 2689 ds.do_cluster = True 2690 2691 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2692 # The default value is 1e-25. 2693 ds.set_func_tol = 1e-8 2694 2695 # The maximum number of iterations. 2696 # The default value is 1e7. 2697 ds.set_max_iter = 10000 2698 2699 # The verbosity level. 2700 ds.verbosity = 1 2701 2702 # The rel_change WARNING level. 2703 ds.rel_change = 0.05 2704 2705 # The plot_curves. 2706 ds.plot_curves = False 2707 2708 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2709 ds.sherekhan_input = False 2710 2711 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2712 ds.opendx = False 2713 2714 # The set r2eff err. 2715 ds.r2eff_err = 0.1 2716 2717 # The print result info. 2718 ds.print_res = False 2719 2720 # Execute the script. 2721 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2722 2723 cur_spins = ds.data[2] 2724 # Compare results. 2725 for i in range(len(cur_spins)): 2726 res_name, res_num, spin_name, params = cur_spins[i] 2727 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2728 cur_spin = return_spin(cur_spin_id) 2729 2730 grid_params = ds.grid_results[i][3] 2731 2732 # Extract the clust results. 2733 min_params = ds.clust_results[i][3] 2734 # Now read the parameters. 2735 print("For spin: '%s'"%cur_spin_id) 2736 for mo_param in cur_spin.params: 2737 # The R2 is a dictionary, depending on spectrometer frequency. 2738 if isinstance(getattr(cur_spin, mo_param), dict): 2739 grid_r2 = grid_params[mo_param] 2740 min_r2 = min_params[mo_param] 2741 set_r2 = params[mo_param] 2742 for key, val in list(set_r2.items()): 2743 grid_r2_frq = grid_r2[key] 2744 min_r2_frq = min_r2[key] 2745 set_r2_frq = set_r2[key] 2746 frq = float(key.split(EXP_TYPE_CPMG_SQ+' - ')[-1].split('MHz')[0]) 2747 rel_change = math.sqrt( (min_r2_frq - set_r2_frq)**2/(min_r2_frq)**2 ) 2748 print("%s %s %s %s %.1f GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, frq, grid_r2_frq, min_r2_frq, set_r2_frq, rel_change) ) 2749 if rel_change > ds.rel_change: 2750 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2751 print("###################################") 2752 2753 ## Make test on R2. 2754 self.assertAlmostEqual(set_r2_frq, min_r2_frq, 1) 2755 else: 2756 grid_val = grid_params[mo_param] 2757 min_val = min_params[mo_param] 2758 set_val = params[mo_param] 2759 rel_change = math.sqrt( (min_val - set_val)**2/(min_val)**2 ) 2760 print("%s %s %s %s GRID=%.3f MIN=%.3f SET=%.3f RELC=%.3f"%(cur_spin.model, res_name, cur_spin_id, mo_param, grid_val, min_val, set_val, rel_change) ) 2761 if rel_change > ds.rel_change: 2762 print("WARNING: rel change level is above %.2f, and is %.4f."%(ds.rel_change, rel_change)) 2763 print("###################################") 2764 2765 ## Make test on parameters. 2766 if mo_param == 'dw': 2767 self.assertAlmostEqual(set_val/10, min_val/10, 1) 2768 elif mo_param == 'kex': 2769 self.assertAlmostEqual(set_val/1000, min_val/1000, 1) 2770 elif mo_param == 'pA': 2771 self.assertAlmostEqual(set_val, min_val, 2)
2772 2773
2775 """Test synthetic cpmg data, calling the dx.map function with one or two points. 2776 2777 This script will produce synthetic CPMG R2eff values according to the selected model, and the fit the selected model. 2778 """ 2779 2780 # Reset. 2781 #self.interpreter.reset() 2782 2783 ## Set Experiments. 2784 model_create = MODEL_NS_CPMG_2SITE_EXPANDED 2785 model_analyse = 'CR72' 2786 # Exp 1 2787 sfrq_1 = 599.8908617*1E6 2788 r20_key_1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_1) 2789 time_T2_1 = 0.06 2790 ncycs_1 = [2, 4, 8, 10, 20, 30, 40, 60] 2791 r2eff_err_1 = [0, 0, 0, 0, 0, 0, 0, 0] 2792 exp_1 = [sfrq_1, time_T2_1, ncycs_1, r2eff_err_1] 2793 2794 sfrq_2 = 499.8908617*1E6 2795 r20_key_2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=sfrq_2) 2796 time_T2_2 = 0.05 2797 ncycs_2 = [2, 4, 8, 10, 30, 35, 40, 50] 2798 r2eff_err_2 = [0, 0, 0, 0, 0, 0, 0, 0] 2799 exp_2 = [sfrq_2, time_T2_2, ncycs_2, r2eff_err_2] 2800 2801 # Collect all exps 2802 exps = [exp_1, exp_2] 2803 2804 spins = [ 2805 ['Ala', 1, 'N', {'r2': {r20_key_1:2, r20_key_2:2}, 'r2a': {r20_key_1:2, r20_key_2:2}, 'r2b': {r20_key_1:2, r20_key_2:2}, 'kex': 1000, 'pA': 0.99, 'dw': 2} ] 2806 ] 2807 2808 # Collect the data to be used. 2809 ds.data = [model_create, model_analyse, spins, exps] 2810 2811 # The tmp directory. None is the local directory. 2812 ds.tmpdir = ds.tmpdir 2813 2814 # The results directory. None is the local directory. 2815 #ds.resdir = None 2816 ds.resdir = ds.tmpdir 2817 2818 # Do r20_from_min_r2eff ?. 2819 ds.r20_from_min_r2eff = True 2820 2821 # Remove insignificant level. 2822 ds.insignificance = 0.0 2823 2824 # The grid search size (the number of increments per dimension). 2825 ds.GRID_INC = None 2826 2827 # The do clustering. 2828 ds.do_cluster = False 2829 2830 # The function tolerance. This is used to terminate minimisation once the function value between iterations is less than the tolerance. 2831 # The default value is 1e-25. 2832 ds.set_func_tol = 1e-9 2833 2834 # The maximum number of iterations. 2835 # The default value is 1e7. 2836 ds.set_max_iter = 1000 2837 2838 # The verbosity level. 2839 ds.verbosity = 1 2840 2841 # The rel_change WARNING level. 2842 ds.rel_change = 0.05 2843 2844 # The plot_curves. 2845 ds.plot_curves = False 2846 2847 # The conversion for ShereKhan at http://sherekhan.bionmr.org/. 2848 ds.sherekhan_input = False 2849 2850 # Make a dx map to be opened om OpenDX. To map the hypersurface of chi2, when altering kex, dw and pA. 2851 ds.opendx = False 2852 2853 # The set r2eff err. 2854 ds.r2eff_err = 0.1 2855 2856 # The print result info. 2857 ds.print_res = False 2858 2859 # Execute the script. 2860 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'cpmg_synthetic.py') 2861 2862 # Get the spins. 2863 cur_spins = ds.data[2] 2864 2865 # First switch pipe, since dx.map will go through parameters and end up a "bad" place. :-) 2866 ds.pipe_name_MODEL_MAP = "%s_%s_map"%(ds.pipe_name, model_analyse) 2867 self.interpreter.pipe.copy(pipe_from=ds.pipe_name, pipe_to=ds.pipe_name_MODEL_MAP, bundle_to = ds.pipe_bundle) 2868 self.interpreter.pipe.switch(pipe_name=ds.pipe_name_MODEL_MAP) 2869 2870 # Copy R2eff, but not the original parameters 2871 self.interpreter.value.copy(pipe_from=ds.pipe_name_r2eff, pipe_to=ds.pipe_name_MODEL_MAP, param='r2eff') 2872 2873 # Then select model. 2874 self.interpreter.relax_disp.select_model(model=model_analyse) 2875 2876 # Define dx.map settings. 2877 ds.dx_inc = 4 2878 ds.dx_params = ['dw', 'pA', 'kex'] 2879 2880 res_name, res_num, spin_name, params = cur_spins[0] 2881 cur_spin_id = ":%i@%s"%(res_num, spin_name) 2882 cur_spin = return_spin(cur_spin_id) 2883 2884 print("Params for dx map is") 2885 print(ds.dx_params) 2886 print("Point param for dx map is") 2887 print(ds.dx_set_val) 2888 cur_model = model_analyse.replace(' ', '_') 2889 file_name_map = "%s_map%s" % (cur_model, cur_spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 2890 file_name_point = "%s_point%s" % (cur_model, cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_')) 2891 self.interpreter.dx.map(params=ds.dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=ds.dx_inc, lower=None, upper=None, axis_incs=10, file_prefix=file_name_map, dir=ds.resdir, point=[ds.dx_set_val, ds.dx_clust_val], point_file=file_name_point, create_par_file=True) 2892 2893 ## Check for file creation 2894 # Set filepaths. 2895 map_cfg = ds.tmpdir+sep+file_name_map+".cfg" 2896 map_net = ds.tmpdir+sep+file_name_map+".net" 2897 map_general = ds.tmpdir+sep+file_name_map+".general" 2898 map_par = get_file_path(file_name=file_name_map+".par", dir=ds.tmpdir) 2899 map_plot = get_file_path(file_name=file_name_map+".py", dir=ds.tmpdir) 2900 2901 point_general = ds.tmpdir+sep+file_name_point+".general" 2902 point_point = ds.tmpdir+sep+file_name_point 2903 point_par = get_file_path(file_name=file_name_point+".par", dir=ds.tmpdir) 2904 2905 # Test the files exists. 2906 self.assert_(access(map_cfg, F_OK)) 2907 self.assert_(access(map_net, F_OK)) 2908 self.assert_(access(map_general, F_OK)) 2909 self.assert_(access(map_par, F_OK)) 2910 self.assert_(access(map_plot, F_OK)) 2911 self.assert_(access(point_general, F_OK)) 2912 self.assert_(access(point_point, F_OK)) 2913 self.assert_(access(point_par, F_OK)) 2914 2915 # Open the files for testing. 2916 # Check the cfg file. 2917 print("\nChecking the dx map .cfg file.") 2918 res_file = [ 2919 '//'+"\n", 2920 '//'+"\n", 2921 '// time: Thu May 8 18:55:31 2014'+"\n", 2922 '//'+"\n", 2923 '// version: 3.2.0 (format), 4.3.2 (DX)'+"\n", 2924 '//'+"\n", 2925 '//'+"\n", 2926 '// panel[0]: position = (0.0164,0.0000), size = 0.2521x0.1933, startup = 1, devstyle = 1'+"\n", 2927 '// title: value = Control Panel'+"\n", 2928 '//'+"\n", 2929 '// workspace: width = 251, height = 142'+"\n", 2930 '// layout: snap = 0, width = 50, height = 50, align = NN'+"\n", 2931 '//'+"\n", 2932 '// interactor Selector[1]: num_components = 1, value = 1 '+"\n", 2933 '// selections: maximum = 2, current = 0 '+"\n", 2934 '// option[0]: name = "Colour", value = 1'+"\n", 2935 '// option[1]: name = "Grey", value = 2'+"\n", 2936 '// instance: panel = 0, x = 81, y = 6, style = Scrolled List, vertical = 1, size = 170x136'+"\n", 2937 '// label: value = Colour Selector'+"\n", 2938 '//'+"\n", 2939 '// node Image[3]:'+"\n", 2940 '// title: value = Surface'+"\n", 2941 '// depth: value = 24'+"\n", 2942 '// window: position = (0.0000,0.0400), size = 0.9929x0.9276'+"\n", 2943 ] 2944 file = open(map_cfg, 'r') 2945 lines = file.readlines() 2946 file.close() 2947 for i in range(len(res_file)): 2948 # Skip time point 2949 if i == 2: 2950 continue 2951 self.assertEqual(res_file[i], lines[i]) 2952 2953 print("\nChecking the dx map .general file.") 2954 res_file = [ 2955 'file = CR72_map_1_N'+"\n", 2956 'grid = 5 x 5 x 5'+"\n", 2957 'format = ascii'+"\n", 2958 'interleaving = field'+"\n", 2959 'majority = row'+"\n", 2960 'field = data'+"\n", 2961 'structure = scalar'+"\n", 2962 'type = float'+"\n", 2963 'dependency = positions'+"\n", 2964 'positions = regular, regular, regular, 0, 1, 0, 1, 0, 1'+"\n", 2965 ''+"\n", 2966 'end'+"\n", 2967 ] 2968 file = open(map_general, 'r') 2969 lines = file.readlines() 2970 file.close() 2971 for i in range(len(res_file)): 2972 # Skip time point 2973 #if i == 2: 2974 # continue 2975 self.assertEqual(res_file[i], lines[i]) 2976 2977 print("\nChecking the dx point .general file.") 2978 res_file = [ 2979 'file = CR72_point_1_N'+"\n", 2980 'points = 2'+"\n", 2981 'format = ascii'+"\n", 2982 'interleaving = field'+"\n", 2983 'field = locations, field0'+"\n", 2984 'structure = 3-vector, scalar'+"\n", 2985 'type = float, float'+"\n", 2986 ''+"\n", 2987 'end'+"\n", 2988 ] 2989 file = open(point_general, 'r') 2990 lines = file.readlines() 2991 file.close() 2992 for i in range(len(res_file)): 2993 # Skip time point 2994 #if i == 2: 2995 # continue 2996 self.assertEqual(res_file[i], lines[i]) 2997 2998 print("\nChecking the dx point point file.") 2999 res_file = [ 3000 '0.8 3.92 0.39964 1'+"\n", 3001 '0.76981 3.9169 0.41353 1'+"\n", 3002 ] 3003 file = open(point_point, 'r') 3004 lines = file.readlines() 3005 file.close() 3006 for i in range(len(res_file)): 3007 # Skip time point 3008 #if i == 2: 3009 # continue 3010 self.assertEqual(res_file[i], lines[i]) 3011 3012 print("\nChecking the dx point par file.") 3013 res_file = [ 3014 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3015 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3016 '1 1.92453 0.98961 1034.72206 6396.02770 1 1.92453 0.98961 1034.72206 6396.02770 '+"\n", 3017 ] 3018 res_file2 = [ 3019 '# i dw pA kex chi2 i_sort dw_sort pA_sort kex_sort chi2_sort '+"\n", 3020 '0 2.00000 0.99000 1000.00000 6185.84926 0 2.00000 0.99000 1000.00000 6185.84926 '+"\n", 3021 '1 1.92452 0.98961 1034.72424 6396.02439 1 1.92452 0.98961 1034.72424 6396.02439 '+"\n", 3022 ] # Python 2.5 and 3.1. 3023 file = open(point_par, 'r') 3024 lines = file.readlines() 3025 file.close() 3026 for i in range(len(res_file)): 3027 if lines[i] != res_file[i] and lines[i] != res_file2[i]: 3028 self.assertEqual(res_file[i], lines[i]) 3029 3030 print("\nChecking the matplotlib surface plot file.") 3031 res_file = [ 3032 'from copy import deepcopy'+"\n", 3033 'import numpy as np'+"\n", 3034 'import scipy.interpolate'+"\n", 3035 'from numpy.ma import masked_where'+"\n", 3036 ''+"\n", 3037 'from mpl_toolkits.mplot3d import axes3d'+"\n", 3038 'import matplotlib.pyplot as plt'+"\n", 3039 'from matplotlib import cm'+"\n", 3040 ''+"\n", 3041 '# Open file and get header.'+"\n", 3042 'mapfile_name = "%s.par"'%file_name_map+"\n", 3043 'pointfile_name = "%s.par"'%file_name_point+"\n", 3044 ''+"\n", 3045 ] 3046 file = open(map_plot, 'r') 3047 lines = file.readlines() 3048 file.close() 3049 for i in range(len(res_file)): 3050 self.assertEqual(res_file[i], lines[i])
3051 3052
3054 """Test the curve type detection using the Dr. Flemming Hansen's CPMG fixed time test data.""" 3055 3056 # Reset. 3057 self.interpreter.reset() 3058 3059 # Load the base data. 3060 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen' 3061 self.interpreter.state.load(data_path+sep+'r2eff_values') 3062 3063 # The type. 3064 curve_type = get_curve_type(id='500_133.33.in') 3065 self.assertEqual(curve_type, 'fixed time')
3066 3067
3068 - def test_curve_type_r1rho_exponential(self, model=None):
3069 """Test the curve type detection using the 'M61' exponential test data.""" 3070 3071 # Reset. 3072 self.interpreter.reset() 3073 3074 # Load the base data. 3075 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_on_res_m61' 3076 self.interpreter.state.load(data_path+sep+'r2eff_values') 3077 3078 # The type. 3079 curve_type = get_curve_type(id='nu_2000_ncyc9') 3080 self.assertEqual(curve_type, 'exponential')
3081 3082
3083 - def test_curve_type_r1rho_fixed_time(self, model=None):
3084 """Test the curve type detection using the 'TP02' fixed time test data.""" 3085 3086 # Reset. 3087 self.interpreter.reset() 3088 3089 # Load the base data. 3090 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r1rho_off_res_tp02' 3091 self.interpreter.state.load(data_path+sep+'r2eff_values') 3092 3093 # The type. 3094 curve_type = get_curve_type(id='nu_1000.0_500MHz') 3095 self.assertEqual(curve_type, 'fixed time')
3096 3097
3098 - def test_dpl94_data_to_dpl94(self):
3099 """Test the relaxation dispersion 'DPL94' model curve fitting to fixed time synthetic data.""" 3100 3101 # Fixed time variable. 3102 ds.fixed = True 3103 3104 # Execute the script. 3105 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_dpl94.py') 3106 3107 # The original parameters. 3108 i0 = [100000.0, 20000.0] 3109 r1rho_prime = [2.25, 24.0] 3110 pA = 0.7 3111 kex = 1000.0 3112 delta_omega = [1.0, 2.0] 3113 phi_ex = [] 3114 for i in range(2): 3115 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 3116 3117 # Switch to the 'DPL94' model data pipe, then check for each spin. 3118 self.interpreter.pipe.switch('DPL94 - relax_disp') 3119 spin_index = 0 3120 for spin, spin_id in spin_loop(return_id=True): 3121 # Printout. 3122 print("\nSpin %s." % spin_id) 3123 3124 # Check the fitted parameters. 3125 self.assertAlmostEqual(spin.r2['R1rho - 800.00000000 MHz']/10, r1rho_prime[spin_index]/10, 2) 3126 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 3127 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 3128 3129 # Increment the spin index. 3130 spin_index += 1
3131 3132
3133 - def test_dx_map_clustered(self):
3134 """Test making dx_map for residues under clustered calculation. 3135 3136 This uses CPMG data from: 3137 - Webb H, Tynan-Connolly BM, Lee GM, Farrell D, O'Meara F, Soendergaard CR, Teilum K, Hewage C, McIntosh LP, Nielsen JE 3138 Remeasuring HEWL pK(a) values by NMR spectroscopy: methods, analysis, accuracy, and implications for theoretical pK(a) calculations. 3139 (2011), Proteins: Struct, Funct, Bioinf 79(3):685-702, U{DOI 10.1002/prot.22886<http://dx.doi.org/10.1002/prot.22886>} 3140 """ 3141 3142 # Define path to data 3143 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'HWebb_KTeilum_Proteins_Struct_Funct_Bioinf_2011' 3144 3145 # Read data. 3146 self.interpreter.results.read(prev_data_path + sep + 'FT_-_CR72_-_min_-_128_-_free_spins') 3147 3148 # Get residue of interest. 3149 cur_spin_id = ":%i@%s"%(52, 'N') 3150 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3151 3152 # Get the spin container. 3153 cur_spin = return_spin(cur_spin_id) 3154 3155 # Get the chi2 value 3156 pre_chi2 = cur_spin.chi2 3157 3158 # Then do a local minimisation. 3159 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3160 self.interpreter.minimise.calculate() 3161 3162 # Get the chi2 value after calculation. 3163 calc_chi2 = cur_spin.chi2 3164 3165 # Assert calculation is equal. 3166 self.assertAlmostEqual(pre_chi2, calc_chi2) 3167 3168 # Define dx.map settings. 3169 dx_inc = 2 3170 dx_inc_sides = dx_inc / 2 3171 3172 dx_params = ['dw', 'pA', 'kex'] 3173 dx_point_clustered_min = [cur_spin.dw, cur_spin.pA, cur_spin.kex] 3174 3175 print("Params for dx map is") 3176 print(dx_params) 3177 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3178 print(dx_point_clustered_min) 3179 3180 # Define file_names. 3181 cur_model = 'CR72' 3182 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3183 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3184 3185 # Step-size of parameter is 10 % 3186 param_delta = 0.1 3187 3188 # Determine bounds for lower and upper 3189 lower = [] 3190 upper = [] 3191 for i, param_val in enumerate(dx_point_clustered_min): 3192 param = dx_params[i] 3193 step_val = param_delta * param_val 3194 step_length = step_val * dx_inc_sides 3195 3196 # Calculate value 3197 low_val = param_val - step_length 3198 lower.append(low_val) 3199 3200 upp_val = param_val + step_length 3201 upper.append(upp_val) 3202 3203 print("For param %s, lower=%3.3f, upper=%3.3f, step_value=%3.3f, steps=%i, centered at=%3.3f"% (param, low_val, upp_val, step_val, dx_inc, param_val)) 3204 3205 # If the number of increments are 2, there will be 3 point calculations per parameter. 3206 # Since we have ordered the lower and upper limits on sides of the parameter, the middle index should give us the expected global value. 3207 dx_param_indexes = dx_inc + 1 3208 dx_point_index = dx_inc_sides + 1 3209 3210 # Find the line number. 3211 line = 1 3212 for i in range(1, dx_param_indexes + 1): 3213 for j in range(1, dx_param_indexes + 1): 3214 for k in range(1, dx_param_indexes + 1): 3215 if i == dx_point_index and j == dx_point_index and k == dx_point_index: 3216 line_chi2 = line 3217 # Add to line counter. 3218 line += 1 3219 3220 # Define temporary folder. 3221 result_dir = self.tmpdir 3222 3223 # For testing. 3224 #result_dir = None 3225 #lower = None 3226 #upper = None 3227 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3228 3229 3230 # Then do the map. 3231 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point) 3232 3233 # Print where to locate values. 3234 nr_chi2_val = dx_param_indexes**3 3235 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3236 print("Global chi2=%3.3f, Calc_chi=%3.3f, map_line_chi2=%i" % (pre_chi2, calc_chi2, line_chi2) ) 3237 3238 ## Check for file creation 3239 # Set filepaths. 3240 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3241 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3242 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3243 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3244 3245 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3246 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3247 3248 # Test the files exists. 3249 self.assert_(access(map_cfg, F_OK)) 3250 self.assert_(access(map_net, F_OK)) 3251 self.assert_(access(map_general, F_OK)) 3252 self.assert_(access(point_general, F_OK)) 3253 self.assert_(access(point_point, F_OK)) 3254 3255 # Open the file, and assert the chi2 value is as expected. 3256 get_data = extract_data(file=map_name) 3257 3258 # Extract line 0, column 0. 3259 test = float(get_data[line_chi2-1][0]) 3260 3261 # Assert. 3262 self.assertAlmostEqual(test, pre_chi2, 6)
3263 3264
3266 """Test making dx_map for residues under clustered calculation, and the creation of the parameter file. 3267 3268 U{Task #7860<https://gna.org/task/index.php?7860>} : When dx_map is issued, create a parameter file which maps parameters to chi2 value. 3269 3270 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 3271 """ 3272 3273 # Define path to data 3274 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+'surface_chi2_clustered_fitting' 3275 3276 # Read data. 3277 self.interpreter.results.read(prev_data_path + sep + 'coMDD_-_TSMFK01_-_min_-_32_-_free_spins.bz2') 3278 3279 # Get residue of interest. 3280 cur_spin_id = ":%i@%s"%(65, 'N') 3281 cur_spin_id_str = cur_spin_id .replace('#', '_').replace(':', '_').replace('@', '_') 3282 3283 # Get the spin container. 3284 cur_spin = return_spin(cur_spin_id) 3285 3286 # Get the chi2 value 3287 pre_chi2 = cur_spin.chi2 3288 3289 # Then do a local minimisation. 3290 #self.interpreter.select.spin(":%i@%s"%(2, 'N')) 3291 self.interpreter.minimise.calculate() 3292 3293 # Get the chi2 value after calculation. 3294 calc_chi2 = cur_spin.chi2 3295 3296 # Assert calculation is equal. 3297 self.assertAlmostEqual(pre_chi2, calc_chi2) 3298 3299 # Define dx.map settings. 3300 dx_inc = 2 3301 dx_params = ['dw', 'k_AB', 'r2a'] 3302 dx_point_clustered_min = [cur_spin.dw, cur_spin.k_AB, cur_spin.r2a['SQ CPMG - 499.86214000 MHz']] 3303 3304 print("Params for dx map is") 3305 print(dx_params) 3306 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3307 print(dx_point_clustered_min) 3308 3309 # Define file_names. 3310 cur_model = 'TSMFK01' 3311 file_name_map = "%s_map%s" % (cur_model, cur_spin_id_str) 3312 file_name_point = "%s_point%s" % (cur_model, cur_spin_id_str) 3313 3314 # Determine bounds for lower and upper 3315 lower = [dx_point_clustered_min[0], dx_point_clustered_min[1], dx_point_clustered_min[2]] 3316 upper = [19.0, 2.4, 9.5] 3317 3318 # Define temporary folder. 3319 result_dir = self.tmpdir 3320 3321 # For testing. 3322 #result_dir = None 3323 #self.interpreter.relax_disp.cluster(cluster_id='free spins', spin_id=cur_spin_id) 3324 3325 # Then do the map. 3326 self.interpreter.dx.map(params=dx_params, map_type='Iso3D', spin_id=cur_spin_id, inc=dx_inc, lower=lower, upper=upper, axis_incs=10, file_prefix=file_name_map, dir=result_dir, point=dx_point_clustered_min, point_file=file_name_point, create_par_file=True) 3327 3328 # Print where to locate values. 3329 nr_chi2_val = (dx_inc + 1)**3 3330 print("Nr of chi2 calculations are=%i"%nr_chi2_val) 3331 print("Global chi2=%3.3f, Calc_chi=%3.3f" % (pre_chi2, calc_chi2) ) 3332 3333 ## Check for file creation 3334 # Set filepaths. 3335 map_name = get_file_path(file_name=file_name_map, dir=result_dir) 3336 map_cfg = get_file_path(file_name=file_name_map+".cfg", dir=result_dir) 3337 map_net = get_file_path(file_name=file_name_map+".net", dir=result_dir) 3338 map_general = get_file_path(file_name=file_name_map+".general", dir=result_dir) 3339 map_par = get_file_path(file_name=file_name_map+".par", dir=result_dir) 3340 3341 point_general = get_file_path(file_name=file_name_point+".general", dir=result_dir) 3342 point_point = get_file_path(file_name=file_name_point, dir=result_dir) 3343 3344 # Test the files exists. 3345 self.assert_(access(map_cfg, F_OK)) 3346 self.assert_(access(map_net, F_OK)) 3347 self.assert_(access(map_general, F_OK)) 3348 self.assert_(access(map_par, F_OK)) 3349 self.assert_(access(point_general, F_OK)) 3350 self.assert_(access(point_point, F_OK)) 3351 3352 print("\nParams for dx map is") 3353 print(dx_params) 3354 print("Point param for dx map is, with chi2=%3.3f"%pre_chi2) 3355 print(dx_point_clustered_min, "\n") 3356 3357 # Open the parameter chi2 file, and assert the chi2 value in the sorted parameter file is not lower that than the global minimisation. 3358 get_data = extract_data(file=map_par) 3359 3360 # Extract line 1, column 9. 3361 test = float(get_data[1][9]) 3362 3363 # Print data if map contain a lower value than the global minimised value. 3364 if test < pre_chi2: 3365 print("\nInitial clustered minimised chi2 value is=%3.3f, whereby the minimum map value is=%3.3f\n" % (pre_chi2, test)) 3366 for line in get_data: 3367 print(line)
3368 3369 # Assert that the initial global chi2 is lower than the map value. 3370 3371 # The following test was taken out, since this a particular interesting case. 3372 # There exist a double minimum, where relax has not found the global minimum. 3373 # This is due to not grid searching for R2A, but using the minimum 3374 #self.assert_(pre_chi2 < test) 3375 3376
3377 - def test_estimate_r2eff_err(self):
3378 """Test the user function for estimating R2eff errors from exponential curve fitting. 3379 3380 This follows Task 7822. 3381 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3382 3383 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3384 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3385 """ 3386 3387 # Cluster residues 3388 cluster_ids = [ 3389 ":13@N", 3390 ":15@N", 3391 ":16@N", 3392 ":25@N", 3393 ":26@N", 3394 ":28@N", 3395 ":39@N", 3396 ":40@N", 3397 ":41@N", 3398 ":43@N", 3399 ":44@N", 3400 ":45@N", 3401 ":49@N", 3402 ":52@N", 3403 ":53@N"] 3404 3405 # Load the data. 3406 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3407 3408 # The dispersion models. 3409 MODELS = [MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3410 3411 # The grid search size (the number of increments per dimension). 3412 GRID_INC = None 3413 3414 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3415 MC_NUM = 3 3416 3417 # Model selection technique. 3418 MODSEL = 'AIC' 3419 3420 # Execute the auto-analysis (fast). 3421 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3422 OPT_FUNC_TOL = 1e-25 3423 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3424 OPT_MAX_ITERATIONS = 10000000 3425 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3426 3427 result_dir_name = ds.tmpdir 3428 3429 # Make all spins free 3430 for curspin in cluster_ids: 3431 self.interpreter.relax_disp.cluster('free spins', curspin) 3432 # Shut them down 3433 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 3434 3435 # Select only a subset of spins for global fitting 3436 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3437 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3438 3439 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3440 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3441 3442 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3443 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3444 3445 # Set the model. 3446 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3447 3448 # Check if intensity errors have already been calculated. 3449 check_intensity_errors() 3450 3451 # Do a grid search. 3452 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 3453 3454 # Minimise. 3455 self.interpreter.minimise.execute(min_algor='Newton', constraints=False, verbosity=1) 3456 3457 # Estimate R2eff errors. 3458 self.interpreter.relax_disp.r2eff_err_estimate() 3459 3460 r1_fit = True 3461 3462 # Run the analysis. 3463 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3464 3465 # Verify the data. 3466 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3467 3468
3470 """Test the user function for estimating R2eff errors from exponential curve fitting, via the auto_analyses menu. 3471 3472 This follows Task 7822. 3473 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3474 3475 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3476 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3477 """ 3478 3479 # Cluster residues 3480 cluster_ids = [ 3481 ":13@N", 3482 ":15@N", 3483 ":16@N", 3484 ":25@N", 3485 ":26@N", 3486 ":28@N", 3487 ":39@N", 3488 ":40@N", 3489 ":41@N", 3490 ":43@N", 3491 ":44@N", 3492 ":45@N", 3493 ":49@N", 3494 ":52@N", 3495 ":53@N"] 3496 3497 # Load the data. 3498 #self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 3499 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 3500 3501 # Set pipe name, bundle and type. 3502 pipe_name = 'base pipe' 3503 pipe_bundle = 'relax_disp' 3504 pipe_type = 'relax_disp' 3505 3506 # Create the data pipe. 3507 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 3508 3509 file = data_path + '1_setup_r1rho_GUI.py' 3510 self.interpreter.script(file=file, dir=None) 3511 3512 # The dispersion models. 3513 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 3514 3515 # The grid search size (the number of increments per dimension). 3516 GRID_INC = None 3517 3518 # The number of Monte Carlo simulations to be used for error analysis for exponential curve fitting of R2eff. 3519 # When set to minus 1, estimation of the errors will be extracted from the covariance matrix. 3520 # This is HIGHLY likely to be wrong, but can be used in an initial test fase. 3521 EXP_MC_NUM = -1 3522 3523 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 3524 MC_NUM = 3 3525 3526 # Model selection technique. 3527 MODSEL = 'AIC' 3528 3529 # Execute the auto-analysis (fast). 3530 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 3531 OPT_FUNC_TOL = 1e-25 3532 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 3533 OPT_MAX_ITERATIONS = 10000000 3534 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 3535 3536 # Make all spins free 3537 #for curspin in cluster_ids: 3538 # self.interpreter.relax_disp.cluster('free spins', curspin) 3539 # # Shut them down 3540 # self.interpreter.deselect.spin(spin_id=curspin, boolean='OR', change_all=False) 3541 3542 # Make all spins free 3543 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 3544 3545 # Select only a subset of spins for global fitting 3546 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 3547 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 3548 3549 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 3550 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 3551 3552 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 3553 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 3554 3555 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3556 print(spin_id) 3557 3558 result_dir_name = self.tmpdir 3559 r1_fit = True 3560 3561 # Run the analysis. 3562 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, exp_mc_sim_num=EXP_MC_NUM, modsel=MODSEL, r1_fit=r1_fit) 3563 3564 # Verify the data. 3565 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='direct')
3566 3567
3569 """Test the user function for estimating R2eff and associated errors for exponential curve fitting with different methods. 3570 This is compared with a run where erros are estimated by 2000 Monte Carlo simulations. 3571 3572 This follows Task 7822. 3573 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 3574 3575 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 3576 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 3577 3578 NOTE: The difference in the methods was due to a bug in relax! 3579 U{bug #22554<https://gna.org/bugs/index.php?22554>}. The distribution of intensity with errors in Monte-Carlo simulations are markedly more narrow than expected. 3580 3581 This dataset is old, and includes 2000 Monte-Carlo simulations, which is performed wrong. 3582 """ 3583 3584 # Define data path. 3585 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" +sep+ "R2eff" 3586 3587 # Create pipe. 3588 self.interpreter.pipe.create('MC_2000', 'relax_disp') 3589 3590 # Read results for 2000 MC simulations. 3591 self.interpreter.results.read(prev_data_path + sep + 'results') 3592 3593 # Start dic. 3594 my_dic = {} 3595 param_key_list = [] 3596 3597 # Do boot strapping ? 3598 do_boot = True 3599 if do_boot: 3600 min_algor = 'Newton' 3601 min_options = () 3602 sim_boot = 200 3603 scaling_list = [1.0, 1.0] 3604 3605 # First check sim values. 3606 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3607 # Add key to dic. 3608 my_dic[spin_id] = {} 3609 3610 # Loop over sim. 3611 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3612 # Loop over all exp type. 3613 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3614 # Generate the param_key. 3615 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3616 r2eff_sim_point = r2eff_sim[param_key] 3617 i0_sim_point = cur_spin.r2eff_sim[i][param_key] 3618 3619 # Assert point are higher than 0.0. 3620 #point_info = "r2eff=%3.2f i0=%3.2f, at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f, at sim index %i." % (r2eff_sim_point, i0_sim_point, frq/1E6, offset, point, i) 3621 #print(point_info) 3622 self.assert_(r2eff_sim_point > 0.0) 3623 self.assert_(i0_sim_point > 0.0) 3624 3625 # Get the data. 3626 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3627 # Generate spin string. 3628 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3629 3630 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3631 # Generate the param_key. 3632 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3633 3634 # Loop over all sim, and collect data. 3635 r2eff_sim_l = [] 3636 i0_sim_l = [] 3637 for i, r2eff_sim in enumerate(cur_spin.r2eff_sim): 3638 i0_sim = cur_spin.i0_sim[i] 3639 3640 r2eff_sim_i = r2eff_sim[param_key] 3641 r2eff_sim_l.append(r2eff_sim_i) 3642 i0_sim_i = i0_sim[param_key] 3643 i0_sim_l.append(i0_sim_i) 3644 3645 # Take the standard deviation of all values. 3646 r2eff_sim_err = std(asarray(r2eff_sim_l), ddof=1) 3647 i0_sim_err = std(asarray(i0_sim_l), ddof=1) 3648 3649 # Append key. 3650 param_key_list.append(param_key) 3651 3652 # Add key to dic. 3653 my_dic[spin_id][param_key] = {} 3654 3655 # Get the value. 3656 r2eff = getattr(cur_spin, 'r2eff')[param_key] 3657 r2eff_err = getattr(cur_spin, 'r2eff_err')[param_key] 3658 i0 = getattr(cur_spin, 'i0')[param_key] 3659 i0_err = getattr(cur_spin, 'i0_err')[param_key] 3660 3661 # Save to dic. 3662 my_dic[spin_id][param_key]['r2eff'] = r2eff 3663 my_dic[spin_id][param_key]['r2eff_err'] = r2eff_err 3664 my_dic[spin_id][param_key]['i0'] = i0 3665 my_dic[spin_id][param_key]['i0_err'] = i0_err 3666 my_dic[spin_id][param_key]['r2eff_err_sim'] = r2eff_sim_err 3667 my_dic[spin_id][param_key]['i0_err_sim'] = i0_sim_err 3668 3669 # Assert values are equal 3670 self.assertAlmostEqual(r2eff_sim_err, r2eff_err) 3671 self.assertAlmostEqual(i0_sim_err, i0_err) 3672 3673 if do_boot: 3674 values = [] 3675 errors = [] 3676 times = [] 3677 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 3678 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 3679 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 3680 times.append(time) 3681 3682 # Convert to numpy array. 3683 values = asarray(values) 3684 errors = asarray(errors) 3685 times = asarray(times) 3686 3687 R_m_sim_l = [] 3688 I0_m_sim_l = [] 3689 for j in range(sim_boot): 3690 if j in range(0, 100000, 100): 3691 print("Simulation %i"%j) 3692 # Start minimisation. 3693 3694 # Produce errors 3695 I_err = [] 3696 for j, error in enumerate(errors): 3697 I_error = gauss(values[j], error) 3698 I_err.append(I_error) 3699 # Convert to numpy array. 3700 I_err = asarray(I_err) 3701 3702 x0 = [r2eff, i0] 3703 model = Relax_fit_opt(model='exp', num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3704 3705 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, full_output=True, print_flag=0) 3706 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 3707 R_m_sim_l.append(R_m_sim_j) 3708 I0_m_sim_l.append(I0_m_sim_j) 3709 3710 # Get stats on distribution. 3711 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 3712 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 3713 my_dic[spin_id][param_key]['r2eff_err_boot'] = sigma_R_sim 3714 my_dic[spin_id][param_key]['i0_err_boot'] = sigma_I0_sim 3715 3716 3717 # A new data pipe. 3718 self.interpreter.pipe.copy(pipe_from='MC_2000', pipe_to='r2eff_est') 3719 self.interpreter.pipe.switch(pipe_name='r2eff_est') 3720 3721 # Delete old errors. 3722 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3723 delattr(cur_spin, 'r2eff_err') 3724 delattr(cur_spin, 'i0_err') 3725 3726 # Set the model. 3727 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 3728 3729 # Estimate R2eff and errors. 3730 self.interpreter.relax_disp.r2eff_err_estimate(verbosity=0) 3731 3732 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 3733 # Generate spin string. 3734 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 3735 3736 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 3737 # Generate the param_key. 3738 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 3739 3740 # Get the value. 3741 r2eff_est = getattr(cur_spin, 'r2eff')[param_key] 3742 r2eff_err_est = getattr(cur_spin, 'r2eff_err')[param_key] 3743 i0_est = getattr(cur_spin, 'i0')[param_key] 3744 i0_err_est = getattr(cur_spin, 'i0_err')[param_key] 3745 3746 # Get from dic. 3747 r2eff = my_dic[spin_id][param_key]['r2eff'] 3748 r2eff_err = my_dic[spin_id][param_key]['r2eff_err'] 3749 i0 = my_dic[spin_id][param_key]['i0'] 3750 i0_err = my_dic[spin_id][param_key]['i0_err'] 3751 r2eff_sim_err = my_dic[spin_id][param_key]['r2eff_err_sim'] 3752 i0_sim_err = my_dic[spin_id][param_key]['i0_err_sim'] 3753 3754 if do_boot: 3755 r2eff_boot_err = my_dic[spin_id][param_key]['r2eff_err_boot'] 3756 i0_boot_err = my_dic[spin_id][param_key]['i0_err_boot'] 3757 else: 3758 r2eff_boot_err = 0.0 3759 i0_boot_err = 0.0 3760 3761 print("%s at %3.1f MHz, for offset=%3.3f ppm and dispersion point %-5.1f." % (exp_type, frq/1E6, offset, point) ) 3762 print("r2eff=%3.3f/%3.3f r2eff_err=%3.4f/%3.4f/%3.4f/%3.4f" % (r2eff, r2eff_est, r2eff_err, r2eff_err_est, r2eff_sim_err, r2eff_boot_err) ), 3763 print("i0=%3.3f/%3.3f i0_err=%3.4f/%3.4f/%3.4f/%3.4f\n" % (i0, i0_est, i0_err, i0_err_est, i0_sim_err, i0_boot_err) ) 3764 3765 3766 # Now do it manually. 3767 estimate_r2eff(method='scipy.optimize.leastsq') 3768 3769 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=False) 3770 estimate_r2eff(method='minfx', min_algor='simplex', c_code=True, constraints=False, chi2_jacobian=True) 3771 3772 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=False) 3773 estimate_r2eff(method='minfx', min_algor='simplex', c_code=False, constraints=False, chi2_jacobian=True) 3774 3775 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=False) 3776 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=True, constraints=False, chi2_jacobian=True) 3777 3778 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=False) 3779 estimate_r2eff(method='minfx', min_algor='BFGS', c_code=False, constraints=False, chi2_jacobian=True) 3780 3781 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=False) 3782 estimate_r2eff(method='minfx', min_algor='Newton', c_code=True, constraints=False, chi2_jacobian=True)
3783 3784 3785
3786 - def test_exp_fit(self):
3787 """Test the relaxation dispersion 'exp_fit' model curve fitting.""" 3788 3789 # Execute the script. 3790 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'exp_fit.py') 3791 3792 # The original exponential curve parameters. 3793 res_data = [ 3794 [15., 10., 20000., 25000.], 3795 [12., 11., 50000., 51000.], 3796 [17., 9., 100000., 96000.] 3797 ] 3798 3799 # List of parameters which do not belong to the model. 3800 blacklist = ['cpmg_frqs', 'r2', 'rex', 'kex', 'r2a', 'k_AB', 'dw'] 3801 3802 # Checks for each residue. 3803 for i in range(len(res_data)): 3804 # Printout. 3805 print("\nResidue number %s." % (i+1)) 3806 3807 # Check the fitted parameters. 3808 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_1000.000'], res_data[i][0], places=2) 3809 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].r2eff['r1rho_1200.00000000_0.000_2000.000'], res_data[i][1], places=2) 3810 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_1000.000']/10000, res_data[i][2]/10000, places=3) 3811 self.assertAlmostEqual(cdp.mol[0].res[i].spin[0].i0['r1rho_1200.00000000_0.000_2000.000']/10000, res_data[i][3]/10000, places=3) 3812 3813 # Check the simulation errors. 3814 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_1000.000'] < 5.0) 3815 self.assert_(cdp.mol[0].res[i].spin[0].r2eff_err['r1rho_1200.00000000_0.000_2000.000'] < 5.0) 3816 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_1000.000']/10000 < 5.0) 3817 self.assert_(cdp.mol[0].res[i].spin[0].i0_err['r1rho_1200.00000000_0.000_2000.000']/10000 < 5.0) 3818 3819 # Check that certain parameters are not present. 3820 for param in blacklist: 3821 print("\tChecking for the absence of the '%s' parameter." % param) 3822 self.assert_(not hasattr(cdp.mol[0].res[i].spin[0], param)) 3823 3824 # Check the clustering information. 3825 self.assert_(hasattr(cdp, 'clustering')) 3826 keys = ['free spins', 'cluster'] 3827 for key in keys: 3828 self.assert_(key in cdp.clustering) 3829 self.assert_('test' not in cdp.clustering) 3830 self.assertEqual(cdp.clustering['free spins'], [':2@N']) 3831 self.assertEqual(cdp.clustering['cluster'], [':1@N', ':3@N'])
3832 3833
3834 - def test_finite_value(self):
3835 """Test return from C code, when parameters are wrong. This can happen, if minfx takes a wrong step.""" 3836 3837 times = array([ 0.7, 1., 0.8, 0.4, 0.9]) 3838 I = array([ 476.76174875, 372.43328777, 454.20339981, 656.87936253, 419.16726341]) 3839 errors = array([ 9.48032653, 11.34093541, 9.35149017, 10.84867928, 12.17590736]) 3840 3841 scaling_list = [1.0, 1.0] 3842 model = Relax_fit_opt(model='exp', num_params=2, values=I, errors=errors, relax_times=times, scaling_matrix=scaling_list) 3843 3844 R = - 500. 3845 I0 = 1000. 3846 params = [R, I0] 3847 3848 chi2 = model.func(params) 3849 3850 print("The chi2 value returned from C-code for R=%3.2f and I0=%3.2f, then chi2=%3.2f"%(R, I0, chi2)) 3851 self.assertNotEqual(chi2, inf)
3852 3853
3854 - def test_hansen_catia_input(self):
3855 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CATIA. 3856 3857 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3858 """ 3859 3860 # Load the R2eff results file. 3861 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 3862 self.interpreter.results.read(file_name) 3863 self.interpreter.deselect.spin(':4') 3864 3865 # The spin isotopes. 3866 self.interpreter.spin.isotope("15N") 3867 3868 # Generate the input files. 3869 self.interpreter.relax_disp.catia_input(dir=ds.tmpdir, force=True) 3870 3871 # Check the r2eff set files. 3872 print("\nChecking the R2eff input set files.") 3873 files = ['data_set_500.inp', 'data_set_500.inp'] 3874 for file in files: 3875 self.assert_(access(ds.tmpdir+sep+file, F_OK)) 3876 data_set_500 = [ 3877 "ID=500\n", 3878 "Sfrq = 500\n", 3879 "Temperature = 0.0\n", 3880 "Nucleus = N15\n", 3881 "Couplednucleus = H1\n", 3882 "Time_equil = 0.0\n", 3883 "Pwx_cp = 0.0\n", 3884 "Taub = 0.0\n", 3885 "Time_T2 = 0.03\n", 3886 "Xcar = 0.0\n", 3887 "Seqfil = CW_CPMG\n", 3888 "Minerror = (2.%;0.5/s)\n", 3889 "Basis = (Iph_7)\n", 3890 "Format = (0;1;2)\n", 3891 "DataDirectory = /tmp/tmpNjOGNG/input_r2eff\n", 3892 "Data = (\n", 3893 " [70N;spin_70_N_500.cpmg];\n", 3894 " [71N;spin_71_N_500.cpmg];\n", 3895 ")\n", 3896 ] 3897 file = open(ds.tmpdir+sep+files[0]) 3898 lines = file.readlines() 3899 file.close() 3900 for i in range(len(data_set_500)): 3901 # Skip the data directory, as this is a random file name. 3902 if i == 14: 3903 continue 3904 3905 self.assertEqual(data_set_500[i], lines[i]) 3906 3907 # Check the r2eff files. 3908 print("\nChecking the R2eff input files.") 3909 files = ['spin_70_N_500.cpmg', 'spin_70_N_800.cpmg', 'spin_71_N_500.cpmg', 'spin_71_N_800.cpmg'] 3910 for file in files: 3911 self.assert_(access(ds.tmpdir+sep+'input_r2eff'+sep+file, F_OK)) 3912 spin_70_N_500 = [ 3913 "# nu_cpmg(Hz) R2(1/s) Esd(R2)\n", 3914 " 66.666600000000003 16.045540885533605 0.310924686180635\n", 3915 " 133.333300000000008 14.877924861181727 0.303217270671013\n", 3916 " 200.000000000000000 14.357820247260586 0.299894424543361\n", 3917 " 266.666600000000017 12.664494620416516 0.289532060485796\n", 3918 " 333.333300000000008 12.363204802467891 0.287759631749322\n", 3919 " 400.000000000000000 11.092532381134513 0.280514035409862\n", 3920 " 466.666600000000017 10.566090057649893 0.277618625949722\n", 3921 " 533.333300000000008 9.805806894657803 0.273544382200754\n", 3922 " 600.000000000000000 9.564300692201730 0.272276309984954\n", 3923 " 666.666600000000017 9.015633750407980 0.269441511838159\n", 3924 " 733.333300000000008 8.607764958055581 0.267375134391053\n", 3925 " 800.000000000000000 8.279997179221338 0.265739551961997\n", 3926 " 866.666600000000017 8.474535940963516 0.266707642726566\n", 3927 " 933.333300000000008 8.158972897365194 0.265141210539941\n", 3928 "1000.000000000000000 7.988630509501972 0.264304105548559\n", 3929 ] 3930 file = open(ds.tmpdir+sep+'input_r2eff'+sep+files[0]) 3931 lines = file.readlines() 3932 file.close() 3933 for i in range(len(lines)): 3934 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 3935 for i in range(len(spin_70_N_500)): 3936 self.assertEqual(spin_70_N_500[i], lines[i]) 3937 3938 # Check the main file. 3939 print("\nChecking the main CATIA execution file.") 3940 main_file = [ 3941 "ReadDataset(data_set_500.inp)\n", 3942 "ReadDataset(data_set_800.inp)\n", 3943 "ReadParam_Global(ParamGlobal.inp)\n", 3944 "ReadParam_Local(ParamSet1.inp)\n", 3945 "\n", 3946 "FreeLocalParam(all;Omega;false)\n", 3947 "FreeLocalParam(all;R1iph_500;false)\n", 3948 "FreeLocalParam(all;R1iph_800;false)\n", 3949 "\n", 3950 "Minimize(print=y;tol=1e-25;maxiter=10000000)\n", 3951 "\n", 3952 "PrintParam(output/GlobalParam.fit;global)\n", 3953 "PrintParam(output/DeltaOmega.fit;DeltaO)\n", 3954 "PrintData(output/)\n", 3955 "\n", 3956 "ChiSq(all;all)\n", 3957 "exit(0)\n" 3958 ] 3959 file = open("%s%sFit.catia" % (ds.tmpdir, sep)) 3960 lines = file.readlines() 3961 file.close() 3962 for i in range(len(main_file)): 3963 self.assertEqual(main_file[i], lines[i])
3964 3965
3967 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 3968 3969 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 3970 """ 3971 3972 # Set the model. 3973 ds.models = [ 3974 MODEL_NOREX, 3975 MODEL_LM63, 3976 MODEL_CR72, 3977 MODEL_IT99 3978 ] 3979 3980 # Execute the script. 3981 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 3982 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 3983 3984 # The R20 keys. 3985 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 3986 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 3987 3988 # The 'No Rex' model checks. 3989 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 3990 spin70 = return_spin(":70") 3991 spin71 = return_spin(":71") 3992 print("\n\nOptimised parameters:\n") 3993 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 3994 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 3995 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 3996 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 3997 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 3998 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 3999 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4000 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4001 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4002 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4003 4004 # The 'LM63' model checks. 4005 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4006 spin70 = return_spin(":70") 4007 spin71 = return_spin(":71") 4008 print("\n\nOptimised parameters:\n") 4009 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4010 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4011 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4012 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4013 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4014 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4015 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4016 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4017 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4018 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4019 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4020 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4021 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4022 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4023 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4024 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4025 4026 # The 'CR72' model checks. 4027 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4028 spin70 = return_spin(":70") 4029 spin71 = return_spin(":71") 4030 print("\n\nOptimised parameters:\n") 4031 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4032 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4033 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4034 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4035 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4036 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4037 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4038 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4039 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4040 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4041 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4042 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4043 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4044 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4045 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4046 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4047 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4048 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4049 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3)
4050 4051
4053 """Test of the numeric model only dispersion auto-analysis using Dr. Flemming Hansen's CPMG data. 4054 4055 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4056 """ 4057 4058 # Set the model and numeric flag. 4059 ds.models = [ 4060 MODEL_NOREX, 4061 MODEL_CR72, 4062 MODEL_NS_CPMG_2SITE_EXPANDED 4063 ] 4064 ds.numeric_only = True 4065 4066 # Execute the script. 4067 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data.py') 4068 4069 # The R20 keys. 4070 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4071 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4072 4073 # The 'No Rex' model checks. 4074 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4075 spin70 = return_spin(":70") 4076 spin71 = return_spin(":71") 4077 print("\n\nOptimised parameters:\n") 4078 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4079 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4080 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4081 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4082 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4083 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4084 self.assertAlmostEqual(spin70.chi2/10000, 8973.84810025761/10000, 3) 4085 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4086 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4087 self.assertAlmostEqual(spin71.chi2/10000, 3908.00127830003/10000, 3) 4088 4089 # The 'CR72' model checks. 4090 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4091 spin70 = return_spin(":70") 4092 spin71 = return_spin(":71") 4093 print("\n\nOptimised parameters:\n") 4094 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4095 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4096 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4097 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4098 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4099 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4100 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4101 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4102 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4103 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4104 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4105 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4106 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4107 self.assertAlmostEqual(spin71.r2[r20_key1], 5.003171547206, 3) 4108 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797727492, 3) 4109 self.assertAlmostEqual(spin71.pA, 0.985922406455826, 3) 4110 self.assertAlmostEqual(spin71.dw, 2.00500965892672, 2) 4111 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579617/10000, 3) 4112 self.assertAlmostEqual(spin71.chi2, 15.6595374286822, 3) 4113 4114 # The 'NS CPMG 2-site expanded' model checks. 4115 self.interpreter.pipe.switch(pipe_name='NS CPMG 2-site expanded - relax_disp') 4116 spin70 = return_spin(":70") 4117 spin71 = return_spin(":71") 4118 print("\n\nOptimised parameters:\n") 4119 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4120 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4121 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4122 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4123 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4124 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4125 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4126 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95815351460902, 3) 4127 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39649535771294, 3) 4128 self.assertAlmostEqual(spin70.pA, 0.989701014493195, 3) 4129 self.assertAlmostEqual(spin70.dw, 5.67314464776128, 3) 4130 self.assertAlmostEqual(spin70.kex/10000, 1713.65380495429/10000, 3) 4131 self.assertAlmostEqual(spin70.chi2, 52.5106880917473, 3) 4132 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99889337382435, 3) 4133 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89822887466673, 3) 4134 self.assertAlmostEqual(spin71.pA, 0.986709050819695, 3) 4135 self.assertAlmostEqual(spin71.dw, 2.09238266766502, 2) 4136 self.assertAlmostEqual(spin71.kex/10000, 2438.27019901422/10000, 3) 4137 self.assertAlmostEqual(spin71.chi2, 15.1644906963987, 3) 4138 4139 # The final data pipe checks. 4140 self.interpreter.pipe.switch(pipe_name='final - relax_disp') 4141 spin70 = return_spin(":70") 4142 spin71 = return_spin(":71") 4143 self.assertEqual(spin70.model, 'NS CPMG 2-site expanded') 4144 self.assertEqual(spin71.model, 'NS CPMG 2-site expanded')
4145 4146
4148 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data (using the R2eff data directly instead of peak intensities). 4149 4150 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4151 """ 4152 4153 # Set the model. 4154 ds.models = [ 4155 MODEL_NOREX, 4156 MODEL_LM63, 4157 MODEL_CR72, 4158 MODEL_IT99 4159 ] 4160 4161 # Execute the script. 4162 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_r2eff_data.py') 4163 self.interpreter.state.save('analysis_r2eff', dir=ds.tmpdir, force=True) 4164 4165 # The R20 keys. 4166 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4167 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4168 4169 # The 'No Rex' model checks. 4170 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4171 spin70 = return_spin(":70") 4172 spin71 = return_spin(":71") 4173 print("\n\nOptimised parameters:\n") 4174 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4175 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4176 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4177 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4178 self.assertAlmostEqual(spin70.r2[r20_key1], 10.5340593984683, 3) 4179 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112170102734, 3) 4180 self.assertAlmostEqual(spin70.chi2, 8973.84810025761, 3) 4181 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83139953954648, 3) 4182 self.assertAlmostEqual(spin71.r2[r20_key2], 8.90856319376098, 3) 4183 self.assertAlmostEqual(spin71.chi2, 3908.00127830003, 3) 4184 4185 # The 'LM63' model checks. 4186 self.interpreter.pipe.switch(pipe_name='LM63 - relax_disp') 4187 spin70 = return_spin(":70") 4188 spin71 = return_spin(":71") 4189 print("\n\nOptimised parameters:\n") 4190 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4191 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4192 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4193 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4194 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4195 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4196 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74326615264889, 2) 4197 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57331164382438, 2) 4198 self.assertAlmostEqual(spin70.phi_ex, 0.312767653822936, 3) 4199 self.assertAlmostEqual(spin70.kex/10000, 4723.44390412119/10000, 3) 4200 self.assertAlmostEqual(spin70.chi2, 363.534049046805, 3) 4201 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00778024769786, 3) 4202 self.assertAlmostEqual(spin71.r2[r20_key2], 6.83343630016037, 3) 4203 self.assertAlmostEqual(spin71.phi_ex, 0.0553791362097596, 3) 4204 self.assertAlmostEqual(spin71.kex/10000, 2781.67925957068/10000, 3) 4205 self.assertAlmostEqual(spin71.chi2, 17.0776426190574, 3) 4206 4207 # The 'CR72' model checks. 4208 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4209 spin70 = return_spin(":70") 4210 spin71 = return_spin(":71") 4211 print("\n\nOptimised parameters:\n") 4212 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4213 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4214 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4215 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4216 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4217 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4218 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4219 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97233943292193, 3) 4220 self.assertAlmostEqual(spin70.r2[r20_key2], 9.409506394526, 2) 4221 self.assertAlmostEqual(spin70.pA, 0.989856804525044, 3) 4222 self.assertAlmostEqual(spin70.dw, 5.60889078920945, 3) 4223 self.assertAlmostEqual(spin70.kex/10000, 1753.01607073019/10000, 3) 4224 self.assertAlmostEqual(spin70.chi2, 53.8382158551706, 3) 4225 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00317154730225, 3) 4226 self.assertAlmostEqual(spin71.r2[r20_key2], 6.90210797713541, 3) 4227 self.assertAlmostEqual(spin71.pA, 0.985922406429147, 3) 4228 self.assertAlmostEqual(spin71.dw, 2.00500965887772, 2) 4229 self.assertAlmostEqual(spin71.kex/10000, 2481.10839579804/10000, 3) 4230 self.assertAlmostEqual(spin71.chi2, 15.6595374288635, 3)
4231 4232
4234 """Test of the dispersion auto-analysis using Dr. Flemming Hansen's CPMG data with parts missing. 4235 4236 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4237 """ 4238 4239 # Set the model. 4240 ds.models = [ 4241 MODEL_R2EFF, 4242 MODEL_NOREX, 4243 MODEL_CR72, 4244 MODEL_NS_CPMG_2SITE_EXPANDED 4245 ] 4246 4247 # Execute the script. 4248 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'hansen_data_missing.py') 4249 self.interpreter.state.save('analysis_heights', dir=ds.tmpdir, force=True) 4250 4251 # The R20 keys. 4252 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4253 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4254 4255 # The 'No Rex' model checks. 4256 self.interpreter.pipe.switch(pipe_name='No Rex - relax_disp') 4257 spin4 = return_spin(":4") 4258 spin70 = return_spin(":70") 4259 spin71 = return_spin(":71") 4260 print("\n\nOptimised parameters:\n") 4261 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4262 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4263 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4264 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4265 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463084515171, 3) 4266 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63220784651911, 3) 4267 self.assertAlmostEqual(spin4.chi2, 26.7356700694891, 3) 4268 self.assertAlmostEqual(spin70.r2[r20_key1], 10.534285641325, 3) 4269 self.assertAlmostEqual(spin70.r2[r20_key2], 16.1112794857068, 3) 4270 self.assertAlmostEqual(spin70.chi2, 8973.84809774722, 3) 4271 self.assertAlmostEqual(spin71.r2[r20_key1], 5.83136858890037, 3) 4272 self.assertAlmostEqual(spin71.chi2, 182.60081909193, 3) 4273 4274 # The 'CR72' model checks. 4275 self.interpreter.pipe.switch(pipe_name='CR72 - relax_disp') 4276 spin4 = return_spin(":4") 4277 spin70 = return_spin(":70") 4278 spin71 = return_spin(":71") 4279 print("\n\nOptimised parameters:\n") 4280 print("%-20s %-20s %-20s %-20s" % ("Parameter", "Value (:4)", "Value (:70)", "Value (:71)")) 4281 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin4.r2[r20_key1], spin70.r2[r20_key1], spin71.r2[r20_key1])) 4282 print("%-20s %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin4.r2[r20_key2], spin70.r2[r20_key2], spin71.r2[r20_key2])) 4283 print("%-20s %20.15g %20.15g %20.15g" % ("pA", spin4.pA, spin70.pA, spin71.pA)) 4284 print("%-20s %20.15g %20.15g %20.15g" % ("dw", spin4.dw, spin70.dw, spin71.dw)) 4285 print("%-20s %20.15g %20.15g %20.15g" % ("kex", spin4.kex, spin70.kex, spin71.kex)) 4286 print("%-20s %20.15g %20.15g %20.15g\n" % ("chi2", spin4.chi2, spin70.chi2, spin71.chi2)) 4287 self.assertAlmostEqual(spin4.r2[r20_key1], 1.60463650370664, 2) 4288 self.assertAlmostEqual(spin4.r2[r20_key2], 1.63221675941434, 3) 4289 #self.assertAlmostEqual(spin4.pA, 0.818979078699935, 3) # As dw (and kex) is zero, this parameter is not stable. 4290 self.assertAlmostEqual(spin4.dw, 0.0, 2) 4291 self.assertAlmostEqual(spin4.kex/10000, 0.0, 3) 4292 self.assertAlmostEqual(spin4.chi2/100, 26.7356711142038/100, 3) 4293 self.assertAlmostEqual(spin70.r2[r20_key1], 6.97268077496405, 3) 4294 self.assertAlmostEqual(spin70.r2[r20_key2], 9.41028133407727, 3) 4295 self.assertAlmostEqual(spin70.pA, 0.989856641885939, 3) 4296 self.assertAlmostEqual(spin70.dw, 5.60889911049405, 3) 4297 self.assertAlmostEqual(spin70.kex/10000, 1752.62025618632/10000, 3) 4298 self.assertAlmostEqual(spin70.chi2, 53.8382196964083, 3) 4299 self.assertAlmostEqual(spin71.r2[r20_key1], 4.98123328466942, 3) 4300 self.assertAlmostEqual(spin71.pA, 0.996607425484157, 3) 4301 self.assertAlmostEqual(spin71.dw, 4.34346257383825, 2) 4302 self.assertAlmostEqual(spin71.kex/10000, 1936.73197158804/10000, 3) 4303 self.assertAlmostEqual(spin71.chi2, 5.51703791653689, 3)
4304 4305
4307 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 dispersion model. 4308 4309 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4310 """ 4311 4312 # Base data setup. 4313 self.setup_hansen_cpmg_data(model='CR72') 4314 4315 # Alias the spins. 4316 spin70 = return_spin(":70") 4317 spin71 = return_spin(":71") 4318 4319 # The R20 keys. 4320 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4321 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4322 4323 # Set the initial parameter values. 4324 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4325 spin70.pA = 0.9 4326 spin70.dw = 6.0 4327 spin70.kex = 1500.0 4328 spin71.r2 = {r20_key1: 5, r20_key2: 9.0} 4329 spin71.pA = 0.9 4330 spin71.dw = 4.0 4331 spin71.kex = 1900.0 4332 4333 # Low precision optimisation. 4334 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4335 4336 # Printout. 4337 print("\n\nOptimised parameters:\n") 4338 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4339 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4340 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4341 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4342 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4343 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4344 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4345 4346 # Checks for residue :70. 4347 self.assertAlmostEqual(spin70.r2[r20_key1], 6.9724581325007, 4) 4348 self.assertAlmostEqual(spin70.r2[r20_key2], 9.40968331038162, 2) 4349 self.assertAlmostEqual(spin70.pA, 0.989856656702431, 4) 4350 self.assertAlmostEqual(spin70.dw, 5.60885879594746, 3) 4351 self.assertAlmostEqual(spin70.kex/1000, 1752.91052702273/1000, 3) 4352 self.assertAlmostEqual(spin70.chi2, 53.8382133597495, 4) 4353 4354 # Checks for residue :71. 4355 self.assertAlmostEqual(spin71.r2[r20_key1], 5.0030740940524, 4) 4356 self.assertAlmostEqual(spin71.pA, 0.985941082507823, 4) 4357 self.assertAlmostEqual(spin71.dw, 2.00640384113696, 4) 4358 self.assertAlmostEqual(spin71.kex/1000, 2480.79614442041/1000, 4) 4359 self.assertAlmostEqual(spin71.chi2, 15.6595388312451, 4) 4360 4361 # Test the conversion to k_AB from kex and pA. 4362 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4363 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4364 4365 # Test the conversion to k_BA from kex and pA. 4366 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4367 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4368 4369
4371 """Optimisation of Dr. Flemming Hansen's CPMG data to the CR72 full dispersion model. 4372 4373 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4374 """ 4375 4376 # Base data setup. 4377 self.setup_hansen_cpmg_data(model='CR72 full') 4378 4379 # Alias the spins. 4380 spin70 = return_spin(":70") 4381 spin71 = return_spin(":71") 4382 4383 # The R20 keys. 4384 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4385 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4386 4387 # Set the initial parameter values. 4388 spin70.r2a = {r20_key1: 7.0, r20_key2: 9.0} 4389 spin70.r2b = {r20_key1: 7.0, r20_key2: 9.0} 4390 spin70.pA = 0.9 4391 spin70.dw = 6.0 4392 spin70.kex = 1500.0 4393 spin71.r2a = {r20_key1: 5.0, r20_key2: 9.0} 4394 spin71.r2b = {r20_key1: 5.0, r20_key2: 9.0} 4395 spin71.pA = 0.9 4396 spin71.dw = 4.0 4397 spin71.kex = 1900.0 4398 4399 # Low precision optimisation. 4400 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4401 4402 # Printout. 4403 print("\n\nOptimised parameters:\n") 4404 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4405 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4406 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4407 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4408 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4409 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4410 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4411 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4412 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4413 4414 # Checks for residue :70. 4415 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.87485258365614, 4) 4416 self.assertAlmostEqual(spin70.r2b[r20_key1], 1.26075839074614, 4) 4417 self.assertAlmostEqual(spin70.r2a[r20_key2], 8.79580446260797, 4) 4418 self.assertAlmostEqual(spin70.r2b[r20_key2], 51.188411562843, 4) 4419 self.assertAlmostEqual(spin70.pA, 0.989384178573802, 4) 4420 self.assertAlmostEqual(spin70.dw, 5.54738203723682, 4) 4421 self.assertAlmostEqual(spin70.kex/1000, 1831.4566463179/1000, 4) 4422 self.assertAlmostEqual(spin70.chi2, 50.450410782403, 4) 4423 4424 # Checks for residue :71. 4425 self.assertAlmostEqual(spin71.r2a[r20_key1], 5.04185695754972, 4) 4426 self.assertAlmostEqual(spin71.r2b[r20_key1], 1.62857899941921, 4) 4427 self.assertAlmostEqual(spin71.pA, 0.988832866751676, 4) 4428 self.assertAlmostEqual(spin71.dw, 2.24905251856265, 4) 4429 self.assertAlmostEqual(spin71.kex/1000, 2397.64122642946/1000, 4) 4430 self.assertAlmostEqual(spin71.chi2, 15.8586492923672, 4) 4431 4432 # Test the conversion to k_AB from kex and pA. 4433 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4434 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4435 4436 # Test the conversion to k_BA from kex and pA. 4437 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4438 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4439 4440
4442 """Optimisation of Dr. Flemming Hansen's CPMG data to the IT99 dispersion model. 4443 4444 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4445 """ 4446 4447 # Base data setup. 4448 self.setup_hansen_cpmg_data(model='IT99') 4449 4450 # Alias the spins. 4451 spin70 = return_spin(":70") 4452 spin71 = return_spin(":71") 4453 4454 # The R20 keys. 4455 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4456 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4457 4458 # Set the initial parameter values. 4459 spin70.r2 = {r20_key1: 8.8, r20_key2: 16.6} 4460 spin70.dw = 10.0 4461 spin70.pA = 0.5 4462 spin70.tex = 1000.09 4463 spin71.r2 = {r20_key1: 1.0, r20_key2: 1.0} 4464 spin71.dw = 10.0 4465 spin71.pA = 0.95 4466 spin71.tex = 0.1 4467 4468 # Low precision optimisation. 4469 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-10, grad_tol=None, max_iter=10000, constraints=True, scaling=True, verbosity=1) 4470 4471 # Printout. 4472 print("\n\nOptimised parameters:\n") 4473 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4474 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4475 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4476 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4477 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4478 print("%-20s %20.15g %20.15g" % ("tex", spin70.tex, spin71.tex)) 4479 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4480 4481 # Checks for residue :70. 4482 self.assertAlmostEqual(spin70.r2[r20_key1], 7.24471197811838, 4) 4483 self.assertAlmostEqual(spin70.r2[r20_key2], 10.0571040704729, 4) 4484 self.assertAlmostEqual(spin70.dw, 5.2116923222744, 4) 4485 self.assertAlmostEqual(spin70.pA, 0.990253627907212, 4) 4486 self.assertAlmostEqual(spin70.tex*1000, 0.000638394793480444*1000, 4) 4487 self.assertAlmostEqual(spin70.chi2, 93.5135798618747, 4) 4488 4489 # Checks for residue :71. 4490 self.assertAlmostEqual(spin71.r2[r20_key1], 5.05971235970214, 4) 4491 self.assertAlmostEqual(spin71.r2[r20_key2], 6.96641194493447, 4) 4492 self.assertAlmostEqual(spin71.dw, 0.435389946897141, 4) 4493 self.assertAlmostEqual(spin71.pA, 0.500000000213519, 3) 4494 self.assertAlmostEqual(spin71.tex*1000, 0.000372436400585538*1000, 4) 4495 self.assertAlmostEqual(spin71.chi2, 23.7895798801404, 4)
4496 4497
4499 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4500 4501 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4502 """ 4503 4504 # Base data setup. 4505 self.setup_hansen_cpmg_data(model='LM63') 4506 4507 # Alias the spins. 4508 spin70 = return_spin(":70") 4509 spin71 = return_spin(":71") 4510 4511 # The R20 keys. 4512 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4513 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4514 4515 # Set the initial parameter values. 4516 spin70.r2 = {r20_key1: 7.0, r20_key2: 7.0} 4517 spin70.phi_ex = 0.3 4518 spin70.kex = 5000.0 4519 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4520 spin71.phi_ex = 0.1 4521 spin71.kex = 2500.0 4522 4523 # Low precision optimisation. 4524 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4525 4526 # Printout. 4527 print("\n\nOptimised parameters:\n") 4528 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4529 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4530 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4531 print("%-20s %20.15g %20.15g" % ("phi_ex", spin70.phi_ex, spin71.phi_ex)) 4532 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4533 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4534 4535 # Checks for residue :70. 4536 self.assertAlmostEqual(spin70.r2[r20_key1], 6.74362294539099) 4537 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406797067481, 6) 4538 self.assertAlmostEqual(spin70.phi_ex, 0.312733013751449) 4539 self.assertAlmostEqual(spin70.kex/1000, 4723.09897146338/1000, 6) 4540 self.assertAlmostEqual(spin70.chi2, 363.534044873483) 4541 4542 # Checks for residue :71. 4543 self.assertAlmostEqual(spin71.r2[r20_key1], 5.00776657729728, 5) 4544 self.assertAlmostEqual(spin71.phi_ex, 0.0553787825650613, 5) 4545 self.assertAlmostEqual(spin71.kex/1000, 2781.72292994154/1000, 5) 4546 self.assertAlmostEqual(spin71.chi2, 17.0776399916287, 5)
4547 4548
4550 """Optimisation of Dr. Flemming Hansen's CPMG data to the LM63 dispersion model. 4551 4552 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4553 """ 4554 4555 # Base data setup. 4556 self.setup_hansen_cpmg_data(model='LM63 3-site') 4557 4558 # Alias the spins. 4559 spin70 = return_spin(":70") 4560 spin71 = return_spin(":71") 4561 4562 # The R20 keys. 4563 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4564 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4565 4566 ## Set the initial parameter values. 4567 spin70.r2 = {r20_key1: 7.570370921220954, r20_key2: 8.694446951909107} 4568 spin70.phi_ex_B = 0.14872003058250227 4569 spin70.phi_ex_C = 0.1319419923472704 4570 spin70.kB = 4103.672910444741 4571 spin70.kC = 7029.001690726248 4572 spin71.r2 = {r20_key1: 5.1347793381636, r20_key2: 7.156573986051575} 4573 spin71.phi_ex_B = 0.04013553485505605 4574 spin71.phi_ex_C = 0.020050748406928887 4575 spin71.kB = 4045.3007136121364 4576 spin71.kC = 3586.38798270774 4577 4578 #self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 4579 #self.interpreter.minimise.grid_search(lower=None, upper=None, inc=41, constraints=True, verbosity=1) 4580 4581 # Low precision optimisation. 4582 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-25, grad_tol=None, max_iter=10000000, constraints=True, scaling=True, verbosity=1) 4583 4584 # Printout. 4585 print("\n\nOptimised parameters:\n") 4586 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4587 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4588 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4589 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin70.phi_ex_B, spin71.phi_ex_B)) 4590 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin70.phi_ex_C, spin71.phi_ex_C)) 4591 print("%-20s %20.15g %20.15g" % ("kB", spin70.kB, spin71.kB)) 4592 print("%-20s %20.15g %20.15g" % ("kC", spin70.kC, spin71.kC)) 4593 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4594 4595 # Checks for residue :70. 4596 self.assertAlmostEqual(spin70.r2[r20_key1], 6.7436230253685, 5) 4597 self.assertAlmostEqual(spin70.r2[r20_key2], 6.57406813008828, 6) 4598 self.assertAlmostEqual(spin70.phi_ex_B, 0.206304023079778, 5) 4599 self.assertAlmostEqual(spin70.phi_ex_C, 0.106428983339627, 5) 4600 self.assertAlmostEqual(spin70.kB/1000, 4723.09897652589/1000, 6) 4601 self.assertAlmostEqual(spin70.kC/1000, 4723.09876196409/1000, 6) 4602 self.assertAlmostEqual(spin70.chi2, 363.534044873483, 5) 4603 4604 # Checks for residue :71. 4605 self.assertAlmostEqual(spin71.r2[r20_key1], 4.96612095596752, 5) 4606 self.assertAlmostEqual(spin71.phi_ex_B, 0.00398262266512895, 5) 4607 self.assertAlmostEqual(spin71.phi_ex_C, 0.0555791581291262, 5) 4608 self.assertAlmostEqual(spin71.kB/1000, 1323.33195689832/1000, 5) 4609 self.assertAlmostEqual(spin71.kC/1000, 3149.58971568059/1000, 5) 4610 self.assertAlmostEqual(spin71.chi2, 16.2620934464368)
4611 4612
4614 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D' dispersion model. 4615 4616 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4617 """ 4618 4619 # Base data setup. 4620 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D') 4621 4622 # Alias the spins. 4623 spin70 = return_spin(":70") 4624 spin71 = return_spin(":71") 4625 4626 # The R20 keys. 4627 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4628 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4629 4630 # Set the initial parameter values. 4631 spin70.r2 = {r20_key1: 6.994165925, r20_key2: 9.428129427} 4632 spin70.pA = 0.9897754407 4633 spin70.dw = 5.642418428 4634 spin70.kex = 1743.666375 4635 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4636 spin71.pA = 0.9968032899 4637 spin71.dw = 4.577891393 4638 spin71.kex = 1830.044597 4639 4640 # Low precision optimisation. 4641 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4642 4643 # Printout. 4644 print("\n\nOptimised parameters:\n") 4645 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4646 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4647 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4648 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4649 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4650 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4651 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4652 4653 # Checks for residue :70. 4654 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95797760459016, 4) 4655 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39628959312699, 4) 4656 self.assertAlmostEqual(spin70.pA, 0.989700985380975, 4) 4657 self.assertAlmostEqual(spin70.dw, 5.6733714171086, 4) 4658 self.assertAlmostEqual(spin70.kex/1000, 1713.63101361545/1000, 4) 4659 self.assertAlmostEqual(spin70.chi2, 52.5106928523775, 4) 4660 4661 # Checks for residue :71. 4662 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99893565849977, 4) 4663 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89825625944034, 4) 4664 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 4) 4665 self.assertAlmostEqual(spin71.dw, 2.09292495350993, 4) 4666 self.assertAlmostEqual(spin71.kex/1000, 2438.04423541463/1000, 4) 4667 self.assertAlmostEqual(spin71.chi2, 15.164490242352, 4) 4668 4669 # Test the conversion to k_AB from kex and pA. 4670 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4671 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4672 4673 # Test the conversion to k_BA from kex and pA. 4674 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4675 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4676 4677
4679 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site 3D full' dispersion model. 4680 4681 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4682 """ 4683 4684 # Base data setup. 4685 self.setup_hansen_cpmg_data(model='NS CPMG 2-site 3D full') 4686 4687 # Alias the spins. 4688 spin70 = return_spin(":70") 4689 spin71 = return_spin(":71") 4690 4691 # The R20 keys. 4692 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4693 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4694 4695 # Set the initial parameter values. 4696 spin70.r2a = {r20_key1: 6.644753428, r20_key2: 7.891776687} 4697 spin70.r2b = {r20_key1: 7.163478485, r20_key2: 138.5170395} 4698 spin70.pA = 0.9884781357 4699 spin70.dw = 5.456507396 4700 spin70.kex = 1906.521189 4701 spin71.r2a = {r20_key1: 4.99893524108981, r20_key2: 100.0} 4702 spin71.r2b = {r20_key1: 8.27456243639973, r20_key2: 100.0} 4703 spin71.pA = 0.986709616684097 4704 spin71.dw = 2.09245158280905 4705 spin71.kex = 2438.2766211401 4706 4707 # Low precision optimisation. 4708 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4709 4710 # Printout. 4711 print("\n\nOptimised parameters:\n") 4712 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4713 print("%-20s %20.15g %20.15g" % ("R2A (500 MHz)", spin70.r2a[r20_key1], spin71.r2a[r20_key1])) 4714 print("%-20s %20.15g %20.15g" % ("R2B (500 MHz)", spin70.r2b[r20_key1], spin71.r2b[r20_key1])) 4715 print("%-20s %20.15g %20.15g" % ("R2A (800 MHz)", spin70.r2a[r20_key2], spin71.r2a[r20_key2])) 4716 print("%-20s %20.15g %20.15g" % ("R2B (800 MHz)", spin70.r2b[r20_key2], spin71.r2b[r20_key2])) 4717 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4718 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4719 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4720 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4721 4722 # Checks for residue :70. 4723 self.assertAlmostEqual(spin70.r2a[r20_key1], 6.61176004043484, 4) 4724 self.assertAlmostEqual(spin70.r2b[r20_key1], 7.4869316381241, 4) 4725 self.assertAlmostEqual(spin70.r2a[r20_key2], 7.78200386067591, 4) 4726 self.assertAlmostEqual(spin70.r2b[r20_key2], 141.703593742468, 4) 4727 self.assertAlmostEqual(spin70.pA, 0.988404987055969, 4) 4728 self.assertAlmostEqual(spin70.dw, 5.4497360203213, 4) 4729 self.assertAlmostEqual(spin70.kex/1000, 1934.09304607082/1000, 4) 4730 self.assertAlmostEqual(spin70.chi2, 44.6793752187925, 4) 4731 4732 # Checks for residue :71. 4733 self.assertAlmostEqual(spin71.r2a[r20_key1], 4.6013095731966, 4) 4734 self.assertAlmostEqual(spin71.r2b[r20_key1], 13.3245678276332, 4) 4735 self.assertAlmostEqual(spin71.r2a[r20_key2], 2.08243621257779, 4) 4736 self.assertAlmostEqual(spin71.r2b[r20_key2], 153.355765094575, 4) 4737 self.assertAlmostEqual(spin71.pA, 0.9665748685124, 4) 4738 self.assertAlmostEqual(spin71.dw, 1.41898001408953, 4) 4739 self.assertAlmostEqual(spin71.kex/1000, 2580.65795560688/1000, 4) 4740 self.assertAlmostEqual(spin71.chi2, 13.4937006732165, 4) 4741 4742 # Test the conversion to k_AB from kex and pA. 4743 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4744 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4745 4746 # Test the conversion to k_BA from kex and pA. 4747 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4748 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4749 4750
4752 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site expanded' dispersion model. 4753 4754 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4755 """ 4756 4757 # Base data setup. 4758 self.setup_hansen_cpmg_data(model='NS CPMG 2-site expanded') 4759 4760 # Alias the spins. 4761 spin70 = return_spin(":70") 4762 spin71 = return_spin(":71") 4763 4764 # The R20 keys. 4765 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4766 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4767 4768 # Set the initial parameter values. 4769 spin70.r2 = {r20_key1: 7.0, r20_key2: 9.0} 4770 spin70.pA = 0.9 4771 spin70.dw = 6.0 4772 spin70.kex = 1500.0 4773 spin71.r2 = {r20_key1: 5.0, r20_key2: 9.0} 4774 spin71.pA = 0.9 4775 spin71.dw = 4.0 4776 spin71.kex = 1900.0 4777 4778 # Low precision optimisation. 4779 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 4780 4781 # Printout. 4782 print("\n\nOptimised parameters:\n") 4783 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4784 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4785 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4786 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4787 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4788 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4789 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4790 4791 # Checks for residue :70. 4792 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95813330991529, 4) 4793 self.assertAlmostEqual(spin70.r2[r20_key2], 9.39663480561524, 4) 4794 self.assertAlmostEqual(spin70.pA, 0.989700843879574, 4) 4795 self.assertAlmostEqual(spin70.dw, 5.67315878825691, 4) 4796 self.assertAlmostEqual(spin70.kex/1000, 1713.56110716632/1000, 4) 4797 self.assertAlmostEqual(spin70.chi2, 52.5106879242812, 4) 4798 4799 # Checks for residue :71. 4800 self.assertAlmostEqual(spin71.r2[r20_key1], 4.99881666793312, 4) 4801 self.assertAlmostEqual(spin71.r2[r20_key2], 6.89817482453042, 4) 4802 self.assertAlmostEqual(spin71.pA, 0.986712911453639, 4) 4803 self.assertAlmostEqual(spin71.dw, 2.09273069372236, 4) 4804 self.assertAlmostEqual(spin71.kex/1000, 2438.20525930405/1000, 4) 4805 self.assertAlmostEqual(spin71.chi2, 15.1644913030633, 4) 4806 4807 # Test the conversion to k_AB from kex and pA. 4808 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4809 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4810 4811 # Test the conversion to k_BA from kex and pA. 4812 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4813 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4814 4815
4817 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star' dispersion model. 4818 4819 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4820 """ 4821 4822 # Base data setup. 4823 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star') 4824 4825 # Alias the spins. 4826 spin70 = return_spin(":70") 4827 spin71 = return_spin(":71") 4828 4829 # The R20 keys. 4830 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4831 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4832 4833 # Set the initial parameter values. 4834 spin70.r2 = {r20_key1: 6.996327746, r20_key2: 9.452051268} 4835 spin70.pA = 0.9897519798 4836 spin70.dw = 5.644862195 4837 spin70.kex = 1723.820567 4838 spin71.r2 = {r20_key1: 4.978654237, r20_key2: 9.276918959} 4839 spin71.pA = 0.9968032899 4840 spin71.dw = 4.577891393 4841 spin71.kex = 1830.044597 4842 4843 # Low precision optimisation. 4844 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=False, scaling=True, verbosity=1) 4845 4846 # Printout. 4847 print("\n\nOptimised parameters:\n") 4848 print("%-20s %-20s %-20s" % ("Parameter", "Value (:70)", "Value (:71)")) 4849 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin70.r2[r20_key1], spin71.r2[r20_key1])) 4850 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin70.r2[r20_key2], spin71.r2[r20_key2])) 4851 print("%-20s %20.15g %20.15g" % ("pA", spin70.pA, spin71.pA)) 4852 print("%-20s %20.15g %20.15g" % ("dw", spin70.dw, spin71.dw)) 4853 print("%-20s %20.15g %20.15g" % ("kex", spin70.kex, spin71.kex)) 4854 print("%-20s %20.15g %20.15g\n" % ("chi2", spin70.chi2, spin71.chi2)) 4855 4856 # Checks for residue :70. 4857 self.assertAlmostEqual(spin70.r2[r20_key1], 6.95543947938561, 1) 4858 self.assertAlmostEqual(spin70.r2[r20_key2], 9.38991914134929, 1) 4859 self.assertAlmostEqual(spin70.pA, 0.989702750971153, 3) 4860 self.assertAlmostEqual(spin70.dw, 5.67527122494516, 1) 4861 self.assertAlmostEqual(spin70.kex/1000, 1715.72032391817/1000, 1) 4862 self.assertAlmostEqual(spin70.chi2, 52.5011991483842, 1) 4863 4864 # Checks for residue :71. 4865 self.assertAlmostEqual(spin71.r2[r20_key1], 4.992594256544, 1) 4866 self.assertAlmostEqual(spin71.pA, 0.986716058519642, 2) 4867 self.assertAlmostEqual(spin71.dw/100, 2.09292495350993/100, 2) 4868 self.assertAlmostEqual(spin71.kex/100000, 2438.04423541463/100000, 2) 4869 self.assertAlmostEqual(spin71.chi2/100, 15.1644902423334/100, 1) 4870 4871 # Test the conversion to k_AB from kex and pA. 4872 self.assertEqual(spin70.k_AB, spin70.kex * (1.0 - spin70.pA)) 4873 self.assertEqual(spin71.k_AB, spin71.kex * (1.0 - spin71.pA)) 4874 4875 # Test the conversion to k_BA from kex and pA. 4876 self.assertEqual(spin70.k_BA, spin70.kex * spin70.pA) 4877 self.assertEqual(spin71.k_BA, spin71.kex * spin71.pA)
4878 4879
4881 """Optimisation of Dr. Flemming Hansen's CPMG data to the 'NS CPMG 2-site star full' dispersion model. 4882 4883 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4884 """ 4885 4886 # Base data setup. 4887 self.setup_hansen_cpmg_data(model='NS CPMG 2-site star full') 4888 4889 # Alias the spins. 4890 spin70 = return_spin(":70") 4891 spin71 = return_spin(":71") 4892 4893 # The R20 keys. 4894 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 4895 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 4896 4897 # Set the initial parameter values. 4898 spin70.r2a = {r20_key1: 6.44836878645126, r20_key2: 7.00382877393494} 4899 spin70.r2b = {r20_key1: 12.2083127421994, r20_key2: 199.862962628402} 4900 spin70.pA = 0.987648082613451 4901 spin70.dw = 5.30679853807572 4902 spin70.kex = 2033.25380420666 4903 spin71.r2a = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4904 spin71.r2b = {r20_key1: 4.992594256544, r20_key2: 6.98674718938435} 4905 spin71.pA = 0.992258541625787 4906 spin71.dw = 2.75140650899058 4907 spin71.kex = 2106.60885247431 4908 4909 # Low precision optimisation. 4910 self.interpreter.minimise.calculate() 4911 4912 # Checks for residue :70. 4913 self.assertAlmostEqual(spin70.chi2/10, 45.773987568491123/10, 2) 4914 self.assertAlmostEqual(spin71.chi2/10, 17.329385665659192/10, 2)
4915 4916
4917 - def test_hansen_cpmgfit_input(self):
4918 """Conversion of Dr. Flemming Hansen's CPMG R2eff values into input files for CPMGFit. 4919 4920 This uses the data from Dr. Flemming Hansen's paper at http://dx.doi.org/10.1021/jp074793o. This is CPMG data with a fixed relaxation time period. 4921 """ 4922 4923 # Load the R2eff results file. 4924 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'r2eff_pipe' 4925 self.interpreter.results.read(file_name) 4926 self.interpreter.deselect.spin(':4') 4927 4928 # Set up the model. 4929 self.interpreter.relax_disp.select_model('LM63') 4930 4931 # Generate the input files. 4932 self.interpreter.relax_disp.cpmgfit_input(force=True, dir=ds.tmpdir) 4933 4934 # What the files should contain. 4935 batch_file = ['#! /bin/sh\n', '\n', 'cpmgfit -grid -xmgr -f spin_70_N.in | tee spin_70_N.out\n', 'cpmgfit -grid -xmgr -f spin_71_N.in | tee spin_71_N.out\n'] 4936 spin1 = [ 4937 "title :70@N\n", 4938 "fields 2 11.7432964915 18.7892743865\n", 4939 "function CPMG\n", 4940 "R2 1 10 20\n", 4941 "Rex 0 100.0 100\n", 4942 "Tau 0 10.0 100\n", 4943 "xmgr\n", 4944 "@ xaxis label \"1/tcp (1/ms)\"\n", 4945 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4946 "@ xaxis ticklabel format decimal\n", 4947 "@ yaxis ticklabel format decimal\n", 4948 "@ xaxis ticklabel char size 0.8\n", 4949 "@ yaxis ticklabel char size 0.8\n", 4950 "@ world xmin 0.0\n", 4951 "data\n", 4952 "0.133333 16.045541 0.310925 11.743296 \n", 4953 "0.266667 14.877925 0.303217 11.743296 \n", 4954 "0.400000 14.357820 0.299894 11.743296 \n", 4955 "0.533333 12.664495 0.289532 11.743296 \n", 4956 "0.666667 12.363205 0.287760 11.743296 \n", 4957 "0.800000 11.092532 0.280514 11.743296 \n", 4958 "0.933333 10.566090 0.277619 11.743296 \n", 4959 "1.066667 9.805807 0.273544 11.743296 \n", 4960 "1.200000 9.564301 0.272276 11.743296 \n", 4961 "1.333333 9.015634 0.269442 11.743296 \n", 4962 "1.466667 8.607765 0.267375 11.743296 \n", 4963 "1.600000 8.279997 0.265740 11.743296 \n", 4964 "1.733333 8.474536 0.266708 11.743296 \n", 4965 "1.866667 8.158973 0.265141 11.743296 \n", 4966 "2.000000 7.988631 0.264304 11.743296 \n", 4967 "0.133333 22.224914 0.166231 18.789274 \n", 4968 "0.266667 21.230874 0.162377 18.789274 \n", 4969 "0.400000 20.603704 0.160017 18.789274 \n", 4970 "0.533333 20.327797 0.158996 18.789274 \n", 4971 "0.666667 18.855377 0.153719 18.789274 \n", 4972 "0.800000 18.537531 0.152617 18.789274 \n", 4973 "0.933333 17.508069 0.149138 18.789274 \n", 4974 "1.066667 16.035604 0.144391 18.789274 \n", 4975 "1.200000 15.168192 0.141717 18.789274 \n", 4976 "1.333333 14.431802 0.139516 18.789274 \n", 4977 "1.466667 14.034137 0.138354 18.789274 \n", 4978 "1.600000 12.920148 0.135192 18.789274 \n", 4979 "1.733333 12.653673 0.134456 18.789274 \n", 4980 "1.866667 12.610864 0.134338 18.789274 \n", 4981 "2.000000 11.969303 0.132601 18.789274 \n" 4982 ] 4983 spin2 = [ 4984 "title :71@N\n", 4985 "fields 2 11.7432964915 18.7892743865\n", 4986 "function CPMG\n", 4987 "R2 1 10 20\n", 4988 "Rex 0 100.0 100\n", 4989 "Tau 0 10.0 100\n", 4990 "xmgr\n", 4991 "@ xaxis label \"1/tcp (1/ms)\"\n", 4992 "@ yaxis label \"R2(tcp) (rad/s)\"\n", 4993 "@ xaxis ticklabel format decimal\n", 4994 "@ yaxis ticklabel format decimal\n", 4995 "@ xaxis ticklabel char size 0.8\n", 4996 "@ yaxis ticklabel char size 0.8\n", 4997 "@ world xmin 0.0\n", 4998 "data\n", 4999 "0.133333 7.044342 0.170035 11.743296 \n", 5000 "0.266667 6.781033 0.169228 11.743296 \n", 5001 "0.400000 6.467623 0.168279 11.743296 \n", 5002 "0.533333 6.333340 0.167876 11.743296 \n", 5003 "0.666667 6.323238 0.167846 11.743296 \n", 5004 "0.800000 6.005245 0.166902 11.743296 \n", 5005 "0.933333 5.767052 0.166203 11.743296 \n", 5006 "1.066667 5.476968 0.165361 11.743296 \n", 5007 "1.200000 5.469949 0.165341 11.743296 \n", 5008 "1.333333 5.295113 0.164838 11.743296 \n", 5009 "1.466667 5.435648 0.165242 11.743296 \n", 5010 "1.600000 5.410400 0.165169 11.743296 \n", 5011 "1.733333 5.437554 0.165247 11.743296 \n", 5012 "1.866667 5.176844 0.164501 11.743296 \n", 5013 "2.000000 5.227232 0.164644 11.743296 \n", 5014 "0.133333 11.530903 0.081928 18.789274 \n", 5015 "0.266667 10.983094 0.081041 18.789274 \n", 5016 "0.400000 10.512403 0.080294 18.789274 \n", 5017 "0.533333 9.984805 0.079473 18.789274 \n", 5018 "0.666667 9.573163 0.078845 18.789274 \n", 5019 "0.800000 9.178810 0.078253 18.789274 \n", 5020 "0.933333 8.935719 0.077893 18.789274 \n", 5021 "1.066667 8.610147 0.077416 18.789274 \n", 5022 "1.200000 8.353778 0.077045 18.789274 \n", 5023 "1.333333 8.173729 0.076787 18.789274 \n", 5024 "1.466667 8.091607 0.076670 18.789274 \n", 5025 "1.600000 7.706420 0.076126 18.789274 \n", 5026 "1.733333 7.709125 0.076129 18.789274 \n", 5027 "1.866667 7.610856 0.075992 18.789274 \n", 5028 "2.000000 7.552584 0.075911 18.789274 \n", 5029 ] 5030 5031 # Check the batch file. 5032 print("\nChecking the batch file.") 5033 file = open("%s%sbatch_run.sh" % (ds.tmpdir, sep)) 5034 lines = file.readlines() 5035 file.close() 5036 for i in range(len(lines)): 5037 self.assertEqual(batch_file[i], lines[i]) 5038 5039 # Check spin :70@N. 5040 print("\nChecking the spin :70@N input file.") 5041 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_70_N')) 5042 lines = file.readlines() 5043 file.close() 5044 for i in range(len(spin1)): 5045 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5046 for i in range(len(lines)): 5047 self.assertEqual(spin1[i], lines[i]) 5048 5049 # Check spin :71@N. 5050 print("\nChecking the spin :71@N input file.") 5051 file = open("%s%sspin%s.in" % (ds.tmpdir, sep, '_71_N')) 5052 lines = file.readlines() 5053 file.close() 5054 for i in range(len(lines)): 5055 print("%s\"%s\\n\"," % (" "*12, lines[i][:-1])) 5056 for i in range(len(spin2)): 5057 self.assertEqual(spin2[i], lines[i])
5058 5059
5061 """Optimisation of the Korzhnev et al., 2005 15N DQ CPMG data using the 'NS MMQ 2-site' model. 5062 5063 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5064 5065 Here only the 15N DQ data will be optimised. The values found by cpmg_fit using just this data are: 5066 5067 - r2 = {'500': 9.487269007171426, '600': 11.718267257562591, '800': 13.624551743116887}, 5068 - pA = 0.965402506690231, 5069 - dw = 0.805197170133360, 5070 - dwH = -0.595536627771890, 5071 - kex = 569.003663067619868, 5072 - chi2 = 9.297671357952812. 5073 """ 5074 5075 # Base data setup. 5076 self.setup_korzhnev_2005_data(data_list=['DQ']) 5077 5078 # Alias the spin. 5079 spin = return_spin(":9@N") 5080 5081 # The R20 keys. 5082 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5083 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5084 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5085 5086 # Set the initial parameter values. 5087 spin.r2 = {r20_key1: 9.48527908326952, r20_key2: 11.7135951595536, r20_key3: 13.6153887849344} 5088 spin.pA = 0.965638501551899 5089 spin.dw = 2.8537583461577 5090 spin.dwH = -0.387633062766635 5091 spin.kex = 573.704033851592 5092 5093 # Low precision optimisation. 5094 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5095 5096 # Monte Carlo simulations. 5097 self.interpreter.monte_carlo.setup(number=3) 5098 self.interpreter.monte_carlo.create_data(method='back_calc') 5099 self.interpreter.monte_carlo.initial_values() 5100 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5101 self.interpreter.monte_carlo.error_analysis() 5102 5103 # Plot the dispersion curves. 5104 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5105 5106 # Save the results. 5107 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5108 5109 # Printout. 5110 print("\n\nOptimised parameters:\n") 5111 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5112 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5113 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5114 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5115 print("%-20s %20.15g" % ("pA", spin.pA)) 5116 print("%-20s %20.15g" % ("dw", spin.dw)) 5117 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5118 print("%-20s %20.15g" % ("kex", spin.kex)) 5119 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5120 5121 # Checks for residue :9. 5122 self.assertAlmostEqual(spin.r2[r20_key1], 9.4870656457415, 2) 5123 self.assertAlmostEqual(spin.r2[r20_key2], 11.7183291788929, 2) 5124 self.assertAlmostEqual(spin.r2[r20_key3], 13.6241729933153, 2) 5125 self.assertAlmostEqual(spin.pA, 0.965405468217295, 4) 5126 self.assertAlmostEqual(spin.dw, 2.76835528427355, 1) 5127 self.assertAlmostEqual(spin.dwH, -0.396489341086363, 2) 5128 self.assertAlmostEqual(spin.kex/1000, 569.06937047601/1000, 3) 5129 self.assertAlmostEqual(spin.chi2, 9.29767487125257, 2)
5130 5131
5133 """Optimisation of the Korzhnev et al., 2005 15N MQ CPMG data using the 'NS MMQ 2-site' model. 5134 5135 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5136 5137 Here only the 15N MQ data will be optimised. The values found by cpmg_fit using just this data are: 5138 5139 - r2 = {'500': 5.993083514798655, '600': 6.622184438384841, '800': 8.640765919352019}, 5140 - pA = 0.930027999814003, 5141 - dw = 4.338620619954370, 5142 - dwH = -0.274250775560818, 5143 - kex = 344.613362916544475, 5144 - chi2 = 10.367733168217050. 5145 """ 5146 5147 # Base data setup. 5148 self.setup_korzhnev_2005_data(data_list=['MQ']) 5149 5150 # Alias the spin. 5151 spin = return_spin(":9@N") 5152 5153 # The R20 keys. 5154 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5155 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5156 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5157 5158 # Set the initial parameter values. 5159 spin.r2 = {r20_key1: 6.02016436619016, r20_key2: 6.65421500772308, r20_key3: 8.6729591487622} 5160 spin.pA = 0.930083249288083 5161 spin.dw = 4.33890689462363 5162 spin.dwH = -0.274316585638047 5163 spin.kex = 344.329651956132 5164 5165 # Low precision optimisation. 5166 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5167 5168 # Monte Carlo simulations. 5169 self.interpreter.monte_carlo.setup(number=3) 5170 self.interpreter.monte_carlo.create_data(method='back_calc') 5171 self.interpreter.monte_carlo.initial_values() 5172 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5173 self.interpreter.monte_carlo.error_analysis() 5174 5175 # Plot the dispersion curves. 5176 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5177 5178 # Save the results. 5179 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5180 5181 # Printout. 5182 print("\n\nOptimised parameters:\n") 5183 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5184 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5185 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5186 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5187 print("%-20s %20.15g" % ("pA", spin.pA)) 5188 print("%-20s %20.15g" % ("dw", spin.dw)) 5189 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5190 print("%-20s %20.15g" % ("kex", spin.kex)) 5191 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5192 5193 # Checks for residue :9. 5194 self.assertAlmostEqual(spin.r2[r20_key1], 5.99503641023038, 1) 5195 self.assertAlmostEqual(spin.r2[r20_key2], 6.62432897608527, 1) 5196 self.assertAlmostEqual(spin.r2[r20_key3], 8.64278915809492, 1) 5197 self.assertAlmostEqual(spin.pA, 0.930036474040713, 3) 5198 self.assertAlmostEqual(spin.dw, 4.33848403058432, 2) 5199 self.assertAlmostEqual(spin.dwH, -0.274246558825267, 3) 5200 self.assertAlmostEqual(spin.kex/1000, 344.626563267384/1000, 3) 5201 self.assertAlmostEqual(spin.chi2, 10.3677362372789, 2)
5202 5203
5205 """Optimisation of the Korzhnev et al., 2005 15N SQ CPMG data using the 'NS MMQ 2-site' model. 5206 5207 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5208 5209 Here only the 15N SQ data will be optimised. The values found by cpmg_fit using just this data are: 5210 5211 - r2 = {'500': 8.335037972570017, '600': 8.761366016417508, '800': 10.225001019091822}, 5212 - pA = 0.950003458294991, 5213 - dw = 4.358402855315123, 5214 - kex = 429.906473361926999, 5215 - chi2 = 17.393331915567252. 5216 """ 5217 5218 # Base data setup. 5219 self.setup_korzhnev_2005_data(data_list=['SQ']) 5220 5221 # Alias the spin. 5222 spin = return_spin(":9@N") 5223 5224 # The R20 keys. 5225 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5226 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5227 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5228 5229 # Set the initial parameter values. 5230 spin.r2 = {r20_key1: 8.334232330326190, r20_key2: 8.756773997879968, r20_key3: 10.219320492033058} 5231 spin.pA = 0.950310172115387 5232 spin.dw = 4.356737157889636 5233 spin.kex = 433.176323890829849 5234 5235 # Low precision optimisation. 5236 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5237 5238 # Monte Carlo simulations. 5239 self.interpreter.monte_carlo.setup(number=3) 5240 self.interpreter.monte_carlo.create_data(method='back_calc') 5241 self.interpreter.monte_carlo.initial_values() 5242 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5243 self.interpreter.monte_carlo.error_analysis() 5244 5245 # Plot the dispersion curves. 5246 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5247 5248 # Save the results. 5249 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5250 5251 # Printout. 5252 print("\n\nOptimised parameters:\n") 5253 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5254 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5255 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5256 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5257 print("%-20s %20.15g" % ("pA", spin.pA)) 5258 print("%-20s %20.15g" % ("dw", spin.dw)) 5259 print("%-20s %20.15g" % ("kex", spin.kex)) 5260 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5261 5262 # Checks for residue :9. 5263 self.assertAlmostEqual(spin.r2[r20_key1], 8.33499994313902, 2) 5264 self.assertAlmostEqual(spin.r2[r20_key2], 8.76118738798082, 2) 5265 self.assertAlmostEqual(spin.r2[r20_key3], 10.2250821829928, 1) 5266 self.assertAlmostEqual(spin.pA, 0.950000281516303, 3) 5267 self.assertAlmostEqual(spin.dw, 4.35845318983581, 2) 5268 self.assertAlmostEqual(spin.kex/1000, 429.874510184149/1000, 2) 5269 self.assertAlmostEqual(spin.chi2, 17.3933357984425, 1)
5270 5271
5273 """Optimisation of the Korzhnev et al., 2005 15N ZQ CPMG data using the 'NS MMQ 2-site' model. 5274 5275 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5276 5277 Here only the 15N ZQ data will be optimised. The values found by cpmg_fit using just this data are: 5278 5279 - r2 = {'500': 5.909812628572937, '600': 6.663690132557320, '800': 6.787171647689906}, 5280 - pA = 0.942452612380140, 5281 - dw = 0.858972784230892, 5282 - dwH = 0.087155962730608, 5283 - kex = 373.219151384798920, 5284 - chi2 = 23.863208106025152. 5285 """ 5286 5287 # Base data setup. 5288 self.setup_korzhnev_2005_data(data_list=['ZQ']) 5289 5290 # Alias the spin. 5291 spin = return_spin(":9@N") 5292 5293 # The R20 keys. 5294 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5295 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5296 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5297 5298 # Set the initial parameter values. 5299 spin.r2 = {r20_key1: 5.91033272691614, r20_key2: 6.66368695342258, r20_key3: 6.78922219135537} 5300 spin.pA = 0.942457332074014 5301 spin.dw = 0.850592422908884 5302 spin.dwH = 0.0881272284455416 5303 spin.kex = 372.745483351305 5304 5305 # Low precision optimisation. 5306 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5307 5308 # Monte Carlo simulations. 5309 self.interpreter.monte_carlo.setup(number=3) 5310 self.interpreter.monte_carlo.create_data(method='back_calc') 5311 self.interpreter.monte_carlo.initial_values() 5312 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5313 self.interpreter.monte_carlo.error_analysis() 5314 5315 # Plot the dispersion curves. 5316 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5317 5318 # Save the results. 5319 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5320 5321 # Printout. 5322 print("\n\nOptimised parameters:\n") 5323 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5324 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5325 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5326 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5327 print("%-20s %20.15g" % ("pA", spin.pA)) 5328 print("%-20s %20.15g" % ("dw", spin.dw)) 5329 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5330 print("%-20s %20.15g" % ("kex", spin.kex)) 5331 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5332 5333 # Checks for residue :9. 5334 self.assertAlmostEqual(spin.r2[r20_key1], 5.9098385837035, 2) 5335 self.assertAlmostEqual(spin.r2[r20_key2], 6.66377885876553, 2) 5336 self.assertAlmostEqual(spin.r2[r20_key3], 6.78717432941353, 2) 5337 self.assertAlmostEqual(spin.pA, 0.942457141344462, 4) 5338 self.assertAlmostEqual(spin.dw, 0.84442055695814, 1) 5339 self.assertAlmostEqual(spin.dwH, 0.0886367674566058, 2) 5340 self.assertAlmostEqual(spin.kex/1000, 373.243053643367/1000, 3) 5341 self.assertAlmostEqual(spin.chi2, 23.863211604121, 1)
5342 5343
5345 """Optimisation of the Korzhnev et al., 2005 1H MQ CPMG data using the 'NS MMQ 2-site' model. 5346 5347 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5348 5349 Here only the 1H MQ data will be optimised. The values found by cpmg_fit using just this data are: 5350 5351 - r2 = {'500': -0.000016676911302, '600': 0.036594127620440, '800': 2.131014839635728}, 5352 - pA = 0.936911090448340, 5353 - dw = 4.325314846914845, 5354 - dwH = -0.213870168665628, 5355 - kex = 487.361914835074117, 5356 - chi2 = 14.870371897291138. 5357 """ 5358 5359 # Base data setup. 5360 self.setup_korzhnev_2005_data(data_list=['1H MQ']) 5361 5362 # Alias the spin. 5363 spin = return_spin(":9@N") 5364 5365 # The R20 keys. 5366 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5367 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5368 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5369 5370 # Set the initial parameter values. 5371 spin.r2 = {r20_key1: 0.000022585022901, r20_key2: 0.039223196112941, r20_key3: 2.136576686700357} 5372 spin.pA = 0.936884348941701 5373 spin.dw = 4.326454531583964 5374 spin.dwH = -0.214026093221782 5375 spin.kex = 487.043592705469223 5376 5377 # Low precision optimisation. 5378 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=100) 5379 5380 # Monte Carlo simulations. 5381 self.interpreter.monte_carlo.setup(number=3) 5382 self.interpreter.monte_carlo.create_data(method='back_calc') 5383 self.interpreter.monte_carlo.initial_values() 5384 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5385 self.interpreter.monte_carlo.error_analysis() 5386 5387 # Plot the dispersion curves. 5388 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5389 5390 # Save the results. 5391 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5392 5393 # Printout. 5394 print("\n\nOptimised parameters:\n") 5395 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5396 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5397 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5398 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5399 print("%-20s %20.15g" % ("pA", spin.pA)) 5400 print("%-20s %20.15g" % ("dw", spin.dw)) 5401 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5402 print("%-20s %20.15g" % ("kex", spin.kex)) 5403 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5404 5405 # Checks for residue :9. 5406 self.assertAlmostEqual(spin.r2[r20_key1], 2.48493199969936e-05, 4) 5407 self.assertAlmostEqual(spin.r2[r20_key2], 0.0382382195911849, 2) 5408 self.assertAlmostEqual(spin.r2[r20_key3], 2.13397221524655, 2) 5409 self.assertAlmostEqual(spin.pA, 0.936879359956996, 4) 5410 self.assertAlmostEqual(spin.dw, 4.32573362253701, 2) 5411 self.assertAlmostEqual(spin.dwH, -0.213951762275293, 2) 5412 self.assertAlmostEqual(spin.kex/1000, 487.021196851596/1000, 4) 5413 self.assertAlmostEqual(spin.chi2, 14.8704048958378, 2)
5414 5415
5417 """Optimisation of the Korzhnev et al., 2005 1H SQ CPMG data using the 'NS MMQ 2-site' model. 5418 5419 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5420 5421 Here only the 1H SQ data will be optimised. The values found by cpmg_fit using just this data are: 5422 5423 - r2 = {'500': 6.691697587650816, '600': 6.998915158708793, '800': 5.519267837559072}, 5424 - pA = 0.946949480545876, 5425 - dwH = -0.265279672133308, 5426 - kex = 406.548178869750700, 5427 - chi2 = 50.400680290545026. 5428 """ 5429 5430 # Base data setup. 5431 self.setup_korzhnev_2005_data(data_list=['1H SQ']) 5432 5433 # Alias the spin. 5434 spin = return_spin(":9@N") 5435 5436 # The R20 keys. 5437 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5438 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5439 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5440 5441 # Set the initial parameter values. 5442 spin.r2 = {r20_key1: 6.69107911078939, r20_key2: 6.99888898689085, r20_key3: 5.52012880268077} 5443 spin.pA = 0.946990967372467 5444 spin.dwH = -0.265308128403529 5445 spin.kex = 406.843250675648 5446 5447 # Low precision optimisation. 5448 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=1000) 5449 5450 # Monte Carlo simulations. 5451 self.interpreter.monte_carlo.setup(number=3) 5452 self.interpreter.monte_carlo.create_data(method='back_calc') 5453 self.interpreter.monte_carlo.initial_values() 5454 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5455 self.interpreter.monte_carlo.error_analysis() 5456 5457 # Plot the dispersion curves. 5458 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5459 5460 # Save the results. 5461 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5462 5463 # Printout. 5464 print("\n\nOptimised parameters:\n") 5465 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5466 print("%-20s %20.15g" % ("R2 (500 MHz)", spin.r2[r20_key1])) 5467 print("%-20s %20.15g" % ("R2 (600 MHz)", spin.r2[r20_key2])) 5468 print("%-20s %20.15g" % ("R2 (800 MHz)", spin.r2[r20_key3])) 5469 print("%-20s %20.15g" % ("pA", spin.pA)) 5470 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5471 print("%-20s %20.15g" % ("kex", spin.kex)) 5472 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5473 5474 # Checks for residue :9. 5475 self.assertAlmostEqual(spin.r2[r20_key1], 6.69168251154302, 2) 5476 self.assertAlmostEqual(spin.r2[r20_key2], 6.99900388754043, 2) 5477 self.assertAlmostEqual(spin.r2[r20_key3], 5.51921590064843, 2) 5478 self.assertAlmostEqual(spin.pA, 0.946951877648819, 4) 5479 self.assertAlmostEqual(spin.dwH, -0.265280175525516, 3) 5480 self.assertAlmostEqual(spin.kex/1000, 406.566453278183/1000, 2) 5481 self.assertAlmostEqual(spin.chi2, 50.4006836222044, 1)
5482 5483
5485 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5486 5487 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5488 5489 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5490 5491 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5492 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5493 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5494 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5495 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5496 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5497 - pA = 0.943125351763911, 5498 - dw = 4.421827493809807, 5499 - dwH = -0.272637034755752, 5500 - kex = 360.609744568697238, 5501 - chi2 = 162.589570340050813. 5502 """ 5503 5504 # Base data setup. 5505 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5506 5507 # Alias the spin. 5508 spin = return_spin(":9@N") 5509 5510 # The R20 keys. 5511 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5512 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5513 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5514 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5515 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5516 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5517 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5518 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5519 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5520 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5521 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5522 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5523 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5524 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5525 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5526 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5527 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5528 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5529 5530 # Set the initial parameter values. 5531 spin.r2 = { 5532 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5533 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5534 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5535 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5536 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5537 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5538 } 5539 spin.pA = 0.943129019477673 5540 spin.dw = 4.42209952545181 5541 spin.dwH = -0.27258970590969 5542 spin.kex = 360.516132791038 5543 5544 # Low precision optimisation. 5545 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-05, max_iter=10) 5546 5547 # Monte Carlo simulations. 5548 self.interpreter.monte_carlo.setup(number=3) 5549 self.interpreter.monte_carlo.create_data(method='back_calc') 5550 self.interpreter.monte_carlo.initial_values() 5551 self.interpreter.minimise.execute(min_algor='simplex', max_iter=10) 5552 self.interpreter.monte_carlo.error_analysis() 5553 5554 # Plot the dispersion curves. 5555 self.interpreter.relax_disp.plot_disp_curves(dir=ds.tmpdir, force=True) 5556 5557 # Save the results. 5558 self.interpreter.state.save('state', dir=ds.tmpdir, compress_type=1, force=True) 5559 5560 # Printout. 5561 print("\n\nOptimised parameters:\n") 5562 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5563 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5564 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5565 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5566 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5567 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5568 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5569 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5570 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5571 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5572 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5573 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5574 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5575 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5576 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5577 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5578 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5579 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5580 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5581 print("%-20s %20.15g" % ("pA", spin.pA)) 5582 print("%-20s %20.15g" % ("dw", spin.dw)) 5583 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5584 print("%-20s %20.15g" % ("kex", spin.kex)) 5585 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5586 5587 # Checks for residue :9. 5588 self.assertAlmostEqual(spin.r2[r20_key1], 6.67288025927458, 4) 5589 self.assertAlmostEqual(spin.r2[r20_key2], 6.98951408255098, 4) 5590 self.assertAlmostEqual(spin.r2[r20_key3], 5.52959273852704, 4) 5591 self.assertAlmostEqual(spin.r2[r20_key4], 8.39471048876782, 4) 5592 self.assertAlmostEqual(spin.r2[r20_key5], 8.89290699178799, 4) 5593 self.assertAlmostEqual(spin.r2[r20_key6], 10.4077068723693, 4) 5594 self.assertAlmostEqual(spin.r2[r20_key7], 5.93611174376373, 4) 5595 self.assertAlmostEqual(spin.r2[r20_key8], 6.71735669582514, 4) 5596 self.assertAlmostEqual(spin.r2[r20_key9], 6.83835225518265, 4) 5597 self.assertAlmostEqual(spin.r2[r20_key10], 8.59615074668922, 4) 5598 self.assertAlmostEqual(spin.r2[r20_key11], 10.6512137889291, 4) 5599 self.assertAlmostEqual(spin.r2[r20_key12], 12.5710822919109, 4) 5600 self.assertAlmostEqual(spin.r2[r20_key13], 7.85956711501608, 4) 5601 self.assertAlmostEqual(spin.r2[r20_key14], 8.41891642907918, 4) 5602 self.assertAlmostEqual(spin.r2[r20_key15], 11.2362089223038, 4) 5603 self.assertAlmostEqual(spin.r2[r20_key16], 9.1965486378935, 4) 5604 self.assertAlmostEqual(spin.r2[r20_key17], 9.86031627358462, 4) 5605 self.assertAlmostEqual(spin.r2[r20_key18], 11.9752375592575, 4) 5606 self.assertAlmostEqual(spin.pA, 0.943129019477673, 4) 5607 self.assertAlmostEqual(spin.dw, 4.42209952545181, 4) 5608 self.assertAlmostEqual(spin.dwH, -0.27258970590969, 4) 5609 self.assertAlmostEqual(spin.kex/1000, 360.516132791038/1000, 4) 5610 self.assertAlmostEqual(spin.chi2/1000, 162.596331278669/1000, 3)
5611 5612
5614 """Optimisation of all the Korzhnev et al., 2005 CPMG data using the 'NS MMQ 2-site' model. 5615 5616 This uses the data from Dmitry Korzhnev's paper at U{DOI: 10.1021/ja054550e<http://dx.doi.org/10.1021/ja054550e>}. This is the 1H SQ, 15N SQ, ZQ, DQ, 1H MQ and 15N MQ data for residue Asp 9 of the Fyn SH3 domain mutant. 5617 5618 Here all data will be optimised. The values found by cpmg_fit using just this data are: 5619 5620 - r2 = {'H-S 500': 6.671649051677150, 'H-S 600': 6.988634195648529, 'H-S 800': 5.527971316790596, 5621 'N-S 500': 8.394988400015988, 'N-S 600': 8.891359568401835, 'N-S 800': 10.405356669006709, 5622 'NHZ 500': 5.936446687394352, 'NHZ 600': 6.717058062814535, 'NHZ 800': 6.838733853403030, 5623 'NHD 500': 8.593136215779710, 'NHD 600': 10.651511259239674, 'NHD 800': 12.567902357560627, 5624 'HNM 500': 7.851325614877817, 'HNM 600': 8.408803624020202, 'HNM 800': 11.227489645758979, 5625 'NHM 500': 9.189159145380575, 'NHM 600': 9.856814478405868, 'NHM 800': 11.967910041807118}, 5626 - pA = 0.943125351763911, 5627 - dw = 4.421827493809807, 5628 - dwH = -0.272637034755752, 5629 - kex = 360.609744568697238, 5630 - chi2 = 162.589570340050813. 5631 """ 5632 5633 # Base data setup. 5634 self.setup_korzhnev_2005_data(data_list=['SQ', '1H SQ', 'DQ', 'ZQ', 'MQ', '1H MQ']) 5635 5636 # Alias the spin. 5637 spin = return_spin(":9@N") 5638 5639 # The R20 keys. 5640 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=500e6) 5641 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=600e6) 5642 r20_key3 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_SQ, frq=800e6) 5643 r20_key4 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 5644 r20_key5 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=600e6) 5645 r20_key6 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 5646 r20_key7 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=500e6) 5647 r20_key8 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=600e6) 5648 r20_key9 = generate_r20_key(exp_type=EXP_TYPE_CPMG_ZQ, frq=800e6) 5649 r20_key10 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=500e6) 5650 r20_key11 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=600e6) 5651 r20_key12 = generate_r20_key(exp_type=EXP_TYPE_CPMG_DQ, frq=800e6) 5652 r20_key13 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=500e6) 5653 r20_key14 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=600e6) 5654 r20_key15 = generate_r20_key(exp_type=EXP_TYPE_CPMG_PROTON_MQ, frq=800e6) 5655 r20_key16 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=500e6) 5656 r20_key17 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 5657 r20_key18 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 5658 5659 # Set the initial parameter values. 5660 spin.r2 = { 5661 r20_key1: 6.67288025927458, r20_key2: 6.98951408255098, r20_key3: 5.52959273852704, 5662 r20_key4: 8.39471048876782, r20_key5: 8.89290699178799, r20_key6: 10.40770687236930, 5663 r20_key7: 5.93611174376373, r20_key8: 6.71735669582514, r20_key9: 6.83835225518265, 5664 r20_key10: 8.59615074668922, r20_key11: 10.65121378892910, r20_key12: 12.57108229191090, 5665 r20_key13: 7.85956711501608, r20_key14: 8.41891642907918, r20_key15: 11.23620892230380, 5666 r20_key16: 9.19654863789350, r20_key17: 9.86031627358462, r20_key18: 11.97523755925750 5667 } 5668 spin.pA = 0.943129019477673 5669 spin.dw = 4.42209952545181 5670 spin.dwH = -0.27258970590969 5671 spin.kex = 360.516132791038 5672 5673 # Calc the chi2 values at these parameters. 5674 self.interpreter.minimise.calculate(verbosity=1) 5675 5676 # Printout. 5677 print("\n\nOptimised parameters:\n") 5678 print("%-20s %-20s" % ("Parameter", "Value (:9)")) 5679 print("%-20s %20.15g" % ("R2 (1H SQ - 500 MHz)", spin.r2[r20_key1])) 5680 print("%-20s %20.15g" % ("R2 (1H SQ - 600 MHz)", spin.r2[r20_key2])) 5681 print("%-20s %20.15g" % ("R2 (1H SQ - 800 MHz)", spin.r2[r20_key3])) 5682 print("%-20s %20.15g" % ("R2 (SQ - 500 MHz)", spin.r2[r20_key4])) 5683 print("%-20s %20.15g" % ("R2 (SQ - 600 MHz)", spin.r2[r20_key5])) 5684 print("%-20s %20.15g" % ("R2 (SQ - 800 MHz)", spin.r2[r20_key6])) 5685 print("%-20s %20.15g" % ("R2 (ZQ - 500 MHz)", spin.r2[r20_key7])) 5686 print("%-20s %20.15g" % ("R2 (ZQ - 600 MHz)", spin.r2[r20_key8])) 5687 print("%-20s %20.15g" % ("R2 (ZQ - 800 MHz)", spin.r2[r20_key9])) 5688 print("%-20s %20.15g" % ("R2 (DQ - 500 MHz)", spin.r2[r20_key10])) 5689 print("%-20s %20.15g" % ("R2 (DQ - 600 MHz)", spin.r2[r20_key11])) 5690 print("%-20s %20.15g" % ("R2 (DQ - 800 MHz)", spin.r2[r20_key12])) 5691 print("%-20s %20.15g" % ("R2 (1H MQ - 500 MHz)", spin.r2[r20_key13])) 5692 print("%-20s %20.15g" % ("R2 (1H MQ - 600 MHz)", spin.r2[r20_key14])) 5693 print("%-20s %20.15g" % ("R2 (1H MQ - 800 MHz)", spin.r2[r20_key15])) 5694 print("%-20s %20.15g" % ("R2 (MQ - 500 MHz)", spin.r2[r20_key16])) 5695 print("%-20s %20.15g" % ("R2 (MQ - 600 MHz)", spin.r2[r20_key17])) 5696 print("%-20s %20.15g" % ("R2 (MQ - 800 MHz)", spin.r2[r20_key18])) 5697 print("%-20s %20.15g" % ("pA", spin.pA)) 5698 print("%-20s %20.15g" % ("dw", spin.dw)) 5699 print("%-20s %20.15g" % ("dwH", spin.dwH)) 5700 print("%-20s %20.15g" % ("kex", spin.kex)) 5701 print("%-20s %20.15g\n" % ("chi2", spin.chi2)) 5702 5703 # Checks for residue :9. 5704 self.assertAlmostEqual(spin.chi2/1000, 162.511988511609/1000, 3)
5705 5706
5708 """Check of all possible dispersion graphs from optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5709 5710 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5711 5712 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5713 5714 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5715 - 0.483 0.89623903 2.4503699912708878 5716 - 0.545 1.1694838 5717 - 0.545 1.1761503 5718 - 0.622 1.294 5719 - 0.669 1.5176493 5720 - 0.722 1.6238791 5721 - 0.813 1.9395758 5722 - 1.011 2.3558415 10.547000429321157 5723 """ 5724 5725 # Base data setup. 5726 model = 'TSMFK01' 5727 expfolder = "acbp_cpmg_disp_048MGuHCl_40C_041223" 5728 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model=model, expfolder=expfolder) 5729 5730 # Alias the spins. 5731 res61L = cdp.mol[0].res[0].spin[0] 5732 5733 # The R20 keys. 5734 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5735 5736 # Set the initial parameter values. 5737 res61L.r2a = {r20_key1: 8.0} 5738 res61L.dw = 6.5 5739 res61L.k_AB = 2.5 5740 5741 # Low precision optimisation. 5742 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5743 5744 # Start testing all possible combinations of graphs. 5745 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 5746 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 5747 interpolate_types = [INTERPOLATE_DISP] 5748 5749 # Write to temp folder. 5750 result_dir_name = ds.tmpdir 5751 result_folders = [model] 5752 spin_id = ":61@N" 5753 5754 # Loop through all possible combinations of y_axis, x_axis and interpolation. 5755 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'KTeilum_FMPoulsen_MAkke_2006'+sep+expfolder+sep+'check_graphs' 5756 5757 for result_folder in result_folders: 5758 for y_axis in y_axis_types: 5759 for x_axis in x_axis_types: 5760 for interpolate in interpolate_types: 5761 # Determine file name: 5762 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 5763 5764 # Make the file name. 5765 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 5766 5767 # Write the curves. 5768 dir = result_dir_name+sep+result_folder 5769 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 5770 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 5771 5772 # Get the file path. 5773 file_path = get_file_path(file_name, dir) 5774 5775 # Test the plot file exists. 5776 print("Testing file access to graph: %s"%file_path) 5777 self.assert_(access(file_path, F_OK)) 5778 5779 # Now open, and compare content, line by line. 5780 file_prod = open(file_path) 5781 lines_prod = file_prod.readlines() 5782 file_prod.close() 5783 5784 # Define file to compare against. 5785 dir_comp = data_path+sep+result_folder 5786 file_path_comp = get_file_path(file_name, dir_comp) 5787 file_comp = open(file_path_comp) 5788 lines_comp = file_comp.readlines() 5789 file_comp.close() 5790 5791 ## Assert number of lines is equal. 5792 self.assertEqual(len(lines_prod), len(lines_comp)) 5793 for j in range(len(lines_prod)): 5794 # Make the string test 5795 first_char = lines_prod[j][0] 5796 if first_char in ["@", "&"]: 5797 self.assertEqual(lines_prod[j], lines_comp[j]) 5798 else: 5799 # Split string in x, y, error. 5800 # The error would change per run. 5801 x_prod, y_prod, y_prod_err = lines_prod[j].split() 5802 x_comp, y_comp, y_comp_err = lines_comp[j].split() 5803 self.assertAlmostEqual(float(x_prod), float(x_comp)) 5804 self.assertAlmostEqual(float(y_prod), float(y_comp)) 5805 self.assertAlmostEqual(float(y_prod_err), float(y_comp_err))
5806 5807
5809 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5810 5811 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5812 """ 5813 5814 # Base data setup. 5815 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5816 5817 # Alias the spins. 5818 res61L = cdp.mol[0].res[0].spin[0] 5819 5820 # The R20 keys. 5821 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5822 5823 # Set the initial parameter values. 5824 res61L.r2 = {r20_key1: 8.0} 5825 res61L.pA = 0.9 5826 res61L.dw = 6.0 5827 res61L.kex = 600.0 5828 5829 # Low precision optimisation. 5830 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5831 5832 # Printout. 5833 print("\n\nOptimised parameters:\n") 5834 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5835 print("%-20s %20.15g" % ("R2 (600 MHz)", res61L.r2[r20_key1])) 5836 print("%-20s %20.15g" % ("pA", res61L.pA)) 5837 print("%-20s %20.15g" % ("dw", res61L.dw)) 5838 print("%-20s %20.15g" % ("kex", res61L.kex)) 5839 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5840 5841 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5842 self.assertAlmostEqual(res61L.r2[r20_key1], 8.69277980194016, 4) 5843 self.assertAlmostEqual(res61L.pA, 0.9943781590842946, 5) 5844 self.assertAlmostEqual(res61L.dw, 6.389453131263374, 3) 5845 self.assertAlmostEqual(res61L.kex, 609.262167216419, 0) 5846 self.assertAlmostEqual(res61L.chi2, 65.99987828889657, 5) 5847 5848 # Test the conversion to k_AB from kex and pA. 5849 self.assertEqual(res61L.k_AB, res61L.kex * (1.0 - res61L.pA)) 5850 5851 # Test the conversion to k_BA from kex and pA. 5852 self.assertEqual(res61L.k_BA, res61L.kex * res61L.pA)
5853 5854
5856 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5857 5858 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5859 """ 5860 5861 # Base data setup. 5862 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='CR72 full', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5863 5864 # Alias the spins. 5865 res61L = cdp.mol[0].res[0].spin[0] 5866 5867 # The R20 keys. 5868 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5869 5870 # Set the initial parameter values. 5871 res61L.r2a = {r20_key1: 8.0} 5872 res61L.r2b = {r20_key1: 105.0} 5873 res61L.pA = 0.9 5874 res61L.dw = 6.0 5875 res61L.kex = 500.0 5876 5877 # Low precision optimisation. 5878 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5879 5880 # Printout. 5881 print("\n\nOptimised parameters:\n") 5882 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5883 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5884 print("%-20s %20.15g" % ("R2B (600 MHz)", res61L.r2b[r20_key1])) 5885 print("%-20s %20.15g" % ("pA", res61L.pA)) 5886 print("%-20s %20.15g" % ("dw", res61L.dw)) 5887 print("%-20s %20.15g" % ("kex", res61L.kex)) 5888 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5889 5890 # Checks for residue :61. Calculated for 500 Monte Carlo simulations. 5891 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.044428899438309, 0) 5892 self.assertAlmostEqual(res61L.r2b[r20_key1], 105.11894506392449, -2) 5893 self.assertAlmostEqual(res61L.pA, 0.992066883657578, 2) 5894 self.assertAlmostEqual(res61L.dw, 6.389453586338883, 3) 5895 self.assertAlmostEqual(res61L.kex, 513.483608742063, -2) 5896 self.assertAlmostEqual(res61L.chi2, 65.99987828890289, 5)
5897 5898
5900 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5901 5902 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 0.48 M GuHCl (guanidine hydrochloride). 5903 5904 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5905 5906 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5907 - 0.483 0.89623903 2.4503699912708878 5908 - 0.545 1.1694838 5909 - 0.545 1.1761503 5910 - 0.622 1.294 5911 - 0.669 1.5176493 5912 - 0.722 1.6238791 5913 - 0.813 1.9395758 5914 - 1.011 2.3558415 10.547000429321157 5915 """ 5916 5917 # Base data setup. 5918 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_048MGuHCl_40C_041223") 5919 5920 # Alias the spins. 5921 res61L = cdp.mol[0].res[0].spin[0] 5922 5923 # The R20 keys. 5924 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086220e6) 5925 5926 # Set the initial parameter values. 5927 res61L.r2a = {r20_key1: 8.0} 5928 res61L.dw = 6.5 5929 res61L.k_AB = 2.5 5930 5931 # Low precision optimisation. 5932 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5933 5934 # Printout. 5935 print("\n\nOptimised parameters:\n") 5936 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 5937 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 5938 print("%-20s %20.15g" % ("dw", res61L.dw)) 5939 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 5940 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 5941 5942 # Checks for residue :61. Reference values from paper 5943 5944 self.assertAlmostEqual(res61L.k_AB, 2.45, 1)
5945 5946
5948 """Optimisation of Kaare Teilum, Flemming M Poulsen, Mikael Akke 2006 "acyl-CoA binding protein" CPMG data to the CR72 dispersion model. 5949 5950 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0509100103}. This is CPMG data with a fixed relaxation time period. Experiment in 1.01 M GuHCl (guanidine hydrochloride). 5951 5952 The comparison is to Figure 2, which is for dataset with 1 M GuHCl. The reported results are expected to be in rad.s^-1. Conversion into relax stored values is preferably. 5953 5954 Representative 15N CPMG relaxation dispersion curve measured on the cross peaks from residue L61 in folded ACBP at pH 5.3, 1 M GuHCl, and 40C: 5955 5956 1. The dotted line represents a residue-specific fit of all parameters in Eq. 1: 5957 - k_AB = 11.3 +/- 0.7 s^-1, 5958 - dw = (2.45 +/- 0.09) * 10^3 s^-1, 5959 - R2 = 8.0 +/- 0.5 s^-1. 5960 5961 2. The solid line represents a global fit of k_AB to all protein residues and a residue-specific fit of dw and R2.: 5962 - k_AB = 10.55 +/- 0.08 s^-1, 5963 - dw = (2.44 +/- 0.08) * 10^3 s^-1, 5964 - R2 = 8.4 +/- 0.3 s^-1. 5965 5966 Conversion of paper results to relax results is performed by: 5967 5968 - dw(ppm) = dw(rad.s^-1) * 10^6 * 1/(2*pi) * (gyro1H/(gyro15N*spectrometer_freq)) = 2.45E3 * 1E6 / (2 * math.pi) * (26.7522212E7/(-2.7126E7 * 599.8908622E6)) = -6.41 ppm. 5969 5970 Figure 3 shows the ln( k_a [s^-1]) for different concentrations of GuHCl. The precise values are: 5971 5972 - [GuHCL][M] ln(k_a[s^-1]) k_a[s^-1] 5973 - 0.483 0.89623903 2.4503699912708878 5974 - 0.545 1.1694838 5975 - 0.545 1.1761503 5976 - 0.622 1.294 5977 - 0.669 1.5176493 5978 - 0.722 1.6238791 5979 - 0.813 1.9395758 5980 - 1.011 2.3558415 10.547000429321157 5981 """ 5982 5983 # Base data setup. 5984 self.setup_kteilum_fmpoulsen_makke_cpmg_data(model='TSMFK01', expfolder="acbp_cpmg_disp_101MGuHCl_40C_041223") 5985 5986 # Alias the spins. 5987 res61L = cdp.mol[0].res[0].spin[0] 5988 5989 # The R20 keys. 5990 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.89086270e6) 5991 5992 # Set the initial parameter values. 5993 res61L.r2a = {r20_key1: 8.0} 5994 res61L.dw = 6.5 5995 res61L.k_AB = 11.0 5996 5997 # Low precision optimisation. 5998 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 5999 6000 # Printout. 6001 print("\n\nOptimised parameters:\n") 6002 print("%-20s %-20s" % ("Parameter", "Value (:61)")) 6003 print("%-20s %20.15g" % ("R2A (600 MHz)", res61L.r2a[r20_key1])) 6004 print("%-20s %20.15g" % ("dw", res61L.dw)) 6005 print("%-20s %20.15g" % ("k_AB", res61L.k_AB)) 6006 print("%-20s %20.15g\n" % ("chi2", res61L.chi2)) 6007 6008 # Checks for residue :61. Reference values from paper 6009 6010 self.assertAlmostEqual(res61L.r2a[r20_key1], 8.4, 0) 6011 self.assertAlmostEqual(res61L.dw, 6.41, 0) 6012 self.assertAlmostEqual(res61L.k_AB, 10.55, 0)
6013 6014
6015 - def test_lm63_3site_synthetic(self):
6016 """Test the 'LM63 3-site' dispersion model using the pure noise-free synthetic data.""" 6017 6018 # The path to the data files. 6019 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'lm63_3site' 6020 6021 # Load the state file. 6022 self.interpreter.reset() 6023 self.interpreter.state.load(data_path+sep+'r2eff_values') 6024 6025 # A new data pipe. 6026 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to='LM63 3-site', bundle_to='relax_disp') 6027 self.interpreter.pipe.switch(pipe_name='LM63 3-site') 6028 6029 # Set up the model data. 6030 self.interpreter.relax_disp.select_model(model='LM63 3-site') 6031 self.interpreter.value.copy(pipe_from='R2eff - relax_disp', pipe_to='LM63 3-site', param='r2eff') 6032 self.interpreter.spin.isotope('15N') 6033 6034 # Alias the spins. 6035 spin1 = return_spin(":1") 6036 spin2 = return_spin(":2") 6037 6038 # The R20 keys. 6039 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=500e6) 6040 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=800e6) 6041 6042 # Manually set the parameter values. 6043 spin1.r2 = {r20_key1: 12.0, r20_key2: 12.0} 6044 spin1.phi_ex_B = 0.1 6045 spin1.phi_ex_C = 0.5 6046 spin1.kB = 1500.0 6047 spin1.kC = 2500.0 6048 spin2.r2 = {r20_key1: 15.0, r20_key2: 15.0} 6049 spin2.phi_ex_B = 0.1 6050 spin2.phi_ex_C = 0.5 6051 spin2.kB = 1500.0 6052 spin2.kC = 2500.0 6053 6054 # Low precision optimisation. 6055 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-05, grad_tol=None, max_iter=1000, constraints=True, scaling=True, verbosity=1) 6056 6057 # Monte Carlo simulations. 6058 self.interpreter.monte_carlo.setup(number=3) 6059 self.interpreter.monte_carlo.create_data(method='back_calc') 6060 self.interpreter.monte_carlo.initial_values() 6061 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-2, grad_tol=None, max_iter=10, constraints=True, scaling=True, verbosity=1) 6062 self.interpreter.monte_carlo.error_analysis() 6063 6064 # Save the results. 6065 self.interpreter.results.write(file='devnull', compress_type=1, force=True) 6066 6067 # The model checks. 6068 print("\n\nOptimised parameters:\n") 6069 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 6070 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 6071 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 6072 print("%-20s %20.15g %20.15g" % ("phi_ex_B", spin1.phi_ex_B, spin2.phi_ex_B)) 6073 print("%-20s %20.15g %20.15g" % ("phi_ex_C", spin1.phi_ex_C, spin2.phi_ex_C)) 6074 print("%-20s %20.15g %20.15g" % ("kB", spin1.kB, spin2.kB)) 6075 print("%-20s %20.15g %20.15g" % ("kC", spin1.kC, spin2.kC)) 6076 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 6077 self.assertAlmostEqual(spin1.r2[r20_key1], 12.0, 2) 6078 self.assertAlmostEqual(spin1.r2[r20_key2], 12.0, 2) 6079 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6080 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6081 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6082 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6083 self.assertAlmostEqual(spin1.chi2, 0.0, 3) 6084 self.assertAlmostEqual(spin2.r2[r20_key1], 15.0, 3) 6085 self.assertAlmostEqual(spin2.r2[r20_key2], 15.0, 3) 6086 self.assertAlmostEqual(spin1.phi_ex_B, 0.1, 3) 6087 self.assertAlmostEqual(spin1.phi_ex_C, 0.5, 3) 6088 self.assertAlmostEqual(spin1.kB/1000, 1500.0/1000, 3) 6089 self.assertAlmostEqual(spin1.kC/1000, 2500.0/1000, 3) 6090 self.assertAlmostEqual(spin2.chi2, 0.0, 3)
6091 6092
6093 - def test_m61_data_to_m61(self):
6094 """Test the relaxation dispersion 'M61' model curve fitting to fixed time synthetic data.""" 6095 6096 # Fixed time variable. 6097 ds.fixed = True 6098 6099 # Execute the script. 6100 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6101 6102 # The original parameters. 6103 i0 = [100000.0, 20000.0] 6104 r1rho_prime = [2.25, 24.0] 6105 pA = 0.7 6106 kex = 1000.0 6107 delta_omega = [1.0, 2.0] 6108 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6109 phi_ex = [] 6110 for i in range(2): 6111 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6112 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6113 6114 # Switch to the 'R2eff' model data pipe, then check for each spin. 6115 self.interpreter.pipe.switch('R2eff - relax_disp') 6116 spin_index = 0 6117 for spin, spin_id in spin_loop(return_id=True): 6118 # Printout. 6119 print("\nSpin %s." % spin_id) 6120 6121 # Check the fitted parameters. 6122 for i in range(len(keys)): 6123 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6124 6125 # Increment the spin index. 6126 spin_index += 1 6127 6128 # The R20 keys. 6129 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6130 6131 # Switch to the 'M61' model data pipe, then check for each spin. 6132 self.interpreter.pipe.switch('M61 - relax_disp') 6133 spin_index = 0 6134 for spin, spin_id in spin_loop(return_id=True): 6135 # Printout. 6136 print("\nSpin %s." % spin_id) 6137 6138 # Check the fitted parameters. 6139 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6140 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6141 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6142 6143 # Increment the spin index. 6144 spin_index += 1
6145 6146
6147 - def test_m61_exp_data_to_m61(self):
6148 """Test the relaxation dispersion 'M61' model curve fitting to the full exponential synthetic data.""" 6149 6150 # Fixed time variable. 6151 ds.fixed = False 6152 6153 # Single spin optimisation. 6154 ds.single = True 6155 6156 # Execute the script. 6157 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61.py') 6158 6159 # The original parameters. 6160 i0 = [100000.0, 20000.0] 6161 r1rho_prime = [2.25, 24.0] 6162 pA = 0.7 6163 kex = 1000.0 6164 delta_omega = [1.0, 2.0] 6165 keys = ['r1rho_800.00000000_0.000_1000.000', 'r1rho_800.00000000_0.000_1500.000', 'r1rho_800.00000000_0.000_2000.000', 'r1rho_800.00000000_0.000_2500.000', 'r1rho_800.00000000_0.000_3000.000', 'r1rho_800.00000000_0.000_3500.000', 'r1rho_800.00000000_0.000_4000.000', 'r1rho_800.00000000_0.000_4500.000', 'r1rho_800.00000000_0.000_5000.000', 'r1rho_800.00000000_0.000_5500.000', 'r1rho_800.00000000_0.000_6000.000'] 6166 phi_ex = [] 6167 for i in range(2): 6168 phi_ex.append(pA * (1.0 - pA) * delta_omega[i]**2) 6169 rates = [[3.59768160399, 2.85730469783, 2.59328084312, 2.47019857325, 2.40310451058, 2.36256876552, 2.33622716364, 2.31815271355, 2.30521680479, 2.29564174079, 2.28835686631], [29.390726416, 26.4292187913, 25.3731233725, 24.880794293, 24.6124180423, 24.4502750621, 24.3449086546, 24.2726108542, 24.2208672192, 24.1825669632, 24.1534274652]] 6170 6171 # Switch to the 'R2eff' model data pipe, then check for each spin. 6172 self.interpreter.pipe.switch('R2eff - relax_disp') 6173 spin_index = 0 6174 for spin, spin_id in spin_loop(return_id=True): 6175 # Printout. 6176 print("\nSpin %s." % spin_id) 6177 6178 # Check the fitted parameters. 6179 for i in range(len(keys)): 6180 self.assertAlmostEqual(spin.r2eff[keys[i]]/10.0, rates[spin_index][i]/10.0, 2) 6181 6182 # Increment the spin index. 6183 spin_index += 1 6184 6185 # The R20 keys. 6186 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6187 6188 # Switch to the 'M61' model data pipe, then check for each spin. 6189 self.interpreter.pipe.switch('M61 - relax_disp') 6190 spin_index = 0 6191 for spin, spin_id in spin_loop(return_id=True): 6192 # Printout. 6193 print("\nSpin %s." % spin_id) 6194 6195 # Check the fitted parameters. 6196 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6197 self.assertAlmostEqual(spin.phi_ex, phi_ex[spin_index], 2) 6198 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6199 6200 # Increment the spin index. 6201 spin_index += 1
6202 6203
6204 - def test_m61b_data_to_m61b(self):
6205 """Test the relaxation dispersion 'M61 skew' model curve fitting to fixed time synthetic data.""" 6206 6207 # Execute the script. 6208 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_on_res_m61b.py') 6209 6210 # The original parameters. 6211 i0 = [100000.0, 20000.0] 6212 r1rho_prime = [10.0, 24.0] 6213 pA = 0.95 6214 kex = 2000.0 6215 delta_omega = [1.0, 2.0] 6216 6217 # The R20 keys. 6218 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 6219 6220 # Switch to the 'M61 skew' model data pipe, then check for each spin. 6221 self.interpreter.pipe.switch("%s - relax_disp" % MODEL_M61B) 6222 spin_index = 0 6223 for spin, spin_id in spin_loop(return_id=True): 6224 # Printout. 6225 print("\nSpin %s." % spin_id) 6226 6227 # Check the fitted parameters. 6228 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index]/10, 2) 6229 self.assertAlmostEqual(spin.pA, pA, 2) 6230 self.assertAlmostEqual(spin.dw, dw[spin_index], 2) 6231 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 2) 6232 6233 # Increment the spin index. 6234 spin_index += 1
6235 6236
6238 """Test that all models which can nest, have all their parameters converted.""" 6239 6240 # Set the experiment type. 6241 cdp.exp_type_list = EXP_TYPE_LIST 6242 6243 # Get info for all models. 6244 all_models_info = models_info(models=MODEL_LIST_FULL) 6245 6246 # Loop over all models. 6247 print("Printing the listed of nested models for each model.") 6248 print("#########################################") 6249 for model_info in all_models_info: 6250 print("%s"%model_info.model), 6251 print("<-"), 6252 nest_list = model_info.nest_list 6253 if nest_list == None: 6254 nest_list = ["None"] 6255 print(', '.join(map(str, nest_list))) 6256 6257 # Skip if there is no model to nest from. 6258 if nest_list == ["None"]: 6259 continue 6260 6261 # Assign params to variable. 6262 model_params = model_info.params 6263 6264 # Now loop over the nested models. 6265 for nested_model in nest_list: 6266 # Get the params for the nested model. 6267 nested_model_params = MODEL_PARAMS[nested_model] 6268 6269 # Get the dictionary of parameter conversion. 6270 par_dic = nesting_param(model_params=model_params, nested_model_params=nested_model_params) 6271 6272 # Test the number of elements in the dictionary. 6273 self.assertEqual(len(par_dic), len(model_params)) 6274 6275 # Loop over dictionary. 6276 for param in par_dic: 6277 if param != par_dic[param]: 6278 print("Model:'%s', Nested model:'%s', Copying '%s' to '%s'." % (model_info.model, nested_model, par_dic[param], param)) 6279 self.assertNotEqual(par_dic[param], None)
6280 6281
6282 - def test_ns_mmq_3site(self):
6283 """Compare the 'NS MMQ 3-site' dispersion model to synthetic data from cpmg_fit.""" 6284 6285 # Execute the script. 6286 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site.py') 6287 6288 # Check the chi-squared value. 6289 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6290 6291
6292 - def test_ns_mmq_3site_linear(self):
6293 """Compare the 'NS MMQ 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6294 6295 # Execute the script. 6296 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_mmq_3site_linear.py') 6297 6298 # Check the chi-squared value. 6299 self.assertAlmostEqual(cdp.mol[0].res[0].spin[1].chi2, 0.0, 3)
6300 6301
6302 - def test_ns_r1rho_3site(self):
6303 """Compare the 'NS R1rho 3-site' dispersion model to synthetic data from cpmg_fit.""" 6304 6305 # Execute the script. 6306 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site.py') 6307 6308 # Check the chi-squared value. 6309 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 136.13141468674999, 3)
6310 6311
6312 - def test_ns_r1rho_3site_linear(self):
6313 """Compare the 'NS R1rho 3-site linear' dispersion model to synthetic data from cpmg_fit.""" 6314 6315 # Execute the script. 6316 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'ns_r1rho_3site_linear.py') 6317 6318 # Check the chi-squared value. 6319 self.assertAlmostEqual(cdp.mol[0].res[0].spin[0].chi2, 0.030959849811015544, 3)
6320 6321
6322 - def test_repeat_cpmg(self):
6323 """Test the protocol for repeated dispersion analysis. The class: relax_disp_repeat_cpmg. 6324 6325 U{task #7826<https://gna.org/task/index.php?7826>}. Write an python class for the repeated analysis of dispersion data. 6326 """ 6327 6328 # Reset. 6329 self.interpreter.reset() 6330 6331 # Define base path to files. 6332 base_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1' 6333 6334 # Setup dictionary with settings. 6335 sdic = {} 6336 6337 # Spectrometer frqs in list. 6338 sfrq_1 = 499.86214 6339 sfrq_2 = 599.8908587 6340 sfrqs = [sfrq_1, sfrq_2] 6341 6342 # Store in dictionary. 6343 sdic['sfrqs'] = sfrqs 6344 6345 # Store unit for frq. 6346 sdic['sfrq_unit'] = 'MHz' 6347 6348 # Store exp_type 6349 sdic['exp_type'] = 'SQ CPMG' 6350 6351 # Store spin isotope 6352 sdic['isotope'] = '15N' 6353 6354 # How intensity was measured. 6355 sdic['int_method'] = 'height' 6356 6357 # Define the time for result directory. 6358 sdic['time'] = '2014_09' 6359 6360 # Initialize frq dics. 6361 for frq in sfrqs: 6362 key = DIC_KEY_FORMAT % (frq) 6363 sdic[key] = {} 6364 6365 # Set keys. 6366 e_1 = DIC_KEY_FORMAT % (sfrq_1) 6367 e_2 = DIC_KEY_FORMAT % (sfrq_2) 6368 6369 # Store time T2. 6370 sdic[e_1]['time_T2'] = 0.04 6371 sdic[e_2]['time_T2'] = 0.06 6372 6373 # Set ncyc. 6374 ncyc_1 = array([20, 0, 16, 10, 36, 2, 12, 4, 22, 18, 40, 14, 26, 8, 32, 24, 6, 28, 0]) 6375 ncyc_2 = array([28, 0, 4, 32, 60, 2, 10, 16, 8, 20, 52, 18, 40, 6, 12, 0, 24, 14, 22]) 6376 6377 # Calculate the cpmg_frq and store. 6378 sdic[e_1]['cpmg_frqs'] = ncyc_1 / sdic[e_1]['time_T2'] 6379 sdic[e_2]['cpmg_frqs'] = ncyc_2 / sdic[e_2]['time_T2'] 6380 6381 # Define peak lists. 6382 peaks_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6383 peaks_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'analysis_FT' +sep+ 'ser_files' 6384 sdic[e_1]['peaks_folder'] = peaks_folder_1 6385 sdic[e_2]['peaks_folder'] = peaks_folder_2 6386 6387 # Define folder to all rmsd files. 6388 rmsd_folder_1 = base_path +sep+ 'cpmg_disp_sod1d90a_060518' +sep+ 'cpmg_disp_sod1d90a_060518_normal.fid' +sep+ 'ft2_data' 6389 rmsd_folder_2 = base_path +sep+ 'cpmg_disp_sod1d90a_060521' +sep+ 'cpmg_disp_sod1d90a_060521_normal.fid' +sep+ 'ft2_data' 6390 sdic[e_1]['rmsd_folder'] = rmsd_folder_1 6391 sdic[e_2]['rmsd_folder'] = rmsd_folder_2 6392 6393 # Define temporary folder. 6394 sdic['results_dir'] = self.tmpdir 6395 6396 # Setup class with data. 6397 RDR = Relax_disp_rep(sdic) 6398 6399 # Setup base information. 6400 RDR.set_base_cpmg(method='FT', glob_ini=128) 6401 6402 methods = ['FT', 'MDD'] 6403 #methods = ['FT'] 6404 6405 # Set the intensity. 6406 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=False, set_rep=True) 6407 #RDR.set_int(methods=methods, list_glob_ini=[128, 126], set_rmsd=True, set_rep=False) 6408 6409 # Try plot some intensity correlations. 6410 if True: 6411 selection = None 6412 6413 # Now make a spin selection. 6414 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128, 126], selection=selection) 6415 6416 # For mdd 6417 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6418 6419 # Plot correlation of intensity 6420 fig1 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 128]] 6421 fig2 = [[int_ft_sel, int_mdd_sel], ['FT', 'MDD'], [128, 126]] 6422 corr_data = [fig1, fig2] 6423 6424 write_stats = True 6425 RDR.plot_int_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6426 6427 # Open stat file. 6428 if write_stats: 6429 for i, corr_data_i in enumerate(corr_data): 6430 data, methods, glob_inis = corr_data[i] 6431 data_x, data_y = data 6432 method_x, method_y = methods 6433 glob_ini_x, glob_ini_y = glob_inis 6434 x = data_x[str(glob_ini_x)]['peak_intensity_arr'] 6435 np = len(x) 6436 6437 file_name_ini = 'int_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6438 6439 if selection == None: 6440 file_name = file_name_ini + '_all.txt' 6441 else: 6442 file_name = file_name_ini + '_sel.txt' 6443 path = RDR.results_dir 6444 data = extract_data(file=file_name, dir=path) 6445 6446 # Loop over the lines. 6447 for i, data_i in enumerate(data): 6448 print(i, data_i) 6449 6450 6451 # Try plot some intensity statistics. 6452 if True: 6453 # Collect r2eff values. 6454 selections = [None, ':2,3'] 6455 for selection in selections: 6456 int_ft_sel = RDR.col_int(method='FT', list_glob_ini=[128], selection=selection) 6457 int_mdd_sel = RDR.col_int(method='MDD', list_glob_ini=[128, 126], selection=selection) 6458 6459 # Get R2eff stats. 6460 int_stat_dic = RDR.get_int_stat_dic(list_int_dics=[int_ft_sel, int_mdd_sel], list_glob_ini=[128, 126]) 6461 6462 ## Plot R2eff stats 6463 write_stats = True 6464 RDR.plot_int_stat(int_stat_dic=int_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126], show=False, write_stats=write_stats) 6465 6466 # Open stat file. 6467 if write_stats: 6468 if selection == None: 6469 file_name = 'int_stat_all.txt' 6470 else: 6471 file_name = 'int_stat_sel.txt' 6472 path = RDR.results_dir 6473 data = extract_data(file=file_name, dir=path) 6474 6475 # Loop over the lines. 6476 for i, data_i in enumerate(data): 6477 print(i, data_i) 6478 6479 6480 # Try write some R2eff correlations. 6481 if True: 6482 selection = None 6483 # Collect r2eff values. 6484 r2eff_ft_all = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6485 6486 # For all spins, mdd 6487 r2eff_mdd_all = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6488 6489 # Plot correlation of intensity 6490 fig1 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 128]] 6491 fig2 = [[r2eff_ft_all, r2eff_mdd_all], ['FT', 'MDD'], [128, 126]] 6492 corr_data = [fig1, fig2] 6493 6494 write_stats = True 6495 RDR.plot_r2eff_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6496 6497 # Open stat file. 6498 if write_stats: 6499 for i, corr_data_i in enumerate(corr_data): 6500 data, methods, glob_inis = corr_data[i] 6501 data_x, data_y = data 6502 method_x, method_y = methods 6503 glob_ini_x, glob_ini_y = glob_inis 6504 x = data_x[str(glob_ini_x)]['r2eff_arr'] 6505 np = len(x) 6506 6507 file_name_ini = 'r2eff_corr_%s_%s_%s_%s_NP_%i' % (method_x, glob_ini_x, method_y, glob_ini_y, np) 6508 6509 if selection == None: 6510 file_name = file_name_ini + '_all.txt' 6511 else: 6512 file_name = file_name_ini + '_sel.txt' 6513 path = RDR.results_dir 6514 data = extract_data(file=file_name, dir=path) 6515 6516 # Loop over the lines. 6517 for i, data_i in enumerate(data): 6518 print(i, data_i) 6519 6520 6521 # Try plot some R2eff statistics. 6522 if True: 6523 # Collect r2eff values. 6524 selections = [None, ':2,3'] 6525 for selection in selections: 6526 r2eff_ft_sel = RDR.col_r2eff(method='FT', list_glob_ini=[128, 126, 6], selection=selection) 6527 r2eff_mdd_sel = RDR.col_r2eff(method='MDD', list_glob_ini=[128, 126], selection=selection) 6528 6529 # Get R2eff stats. 6530 r2eff_stat_dic = RDR.get_r2eff_stat_dic(list_r2eff_dics=[r2eff_ft_sel, r2eff_mdd_sel], list_glob_ini=[128, 126]) 6531 6532 ## Plot R2eff stats 6533 write_stats = True 6534 RDR.plot_r2eff_stat(r2eff_stat_dic=r2eff_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6535 6536 # Open stat file. 6537 if write_stats: 6538 if selection == None: 6539 file_name = 'r2eff_stat_all.txt' 6540 else: 6541 file_name = 'r2eff_stat_sel.txt' 6542 path = RDR.results_dir 6543 data = extract_data(file=file_name, dir=path) 6544 6545 # Loop over the lines. 6546 for i, data_i in enumerate(data): 6547 print(i, data_i) 6548 6549 6550 # Do minimisation individual. 6551 if True: 6552 methods = ['FT', 'MDD'] 6553 # Now calculate R2eff. 6554 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6555 6556 min_methods = [['FT'], ['MDD']] 6557 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6558 6559 #min_methods = [['FT']] 6560 #min_list_glob_ini = [[128]] 6561 #selection = ':2,3' 6562 selection = None 6563 6564 for i, methods in enumerate(min_methods): 6565 list_glob_ini = min_list_glob_ini[i] 6566 6567 if True: 6568 # First get data. 6569 if True: 6570 # First load all data. 6571 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6572 6573 # Then set R20 6574 if True: 6575 # Set R20 from min R2eff in preparation for Grid search. 6576 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, model_from=MODEL_R2EFF, analysis='grid_setup_ind', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6577 6578 # Check and print parameters. 6579 if True: 6580 # Print for pipe name 6581 method = methods[0] 6582 glob_ini = list_glob_ini[0] 6583 6584 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup_ind', glob_ini=glob_ini) 6585 RDR.spin_display_params(pipe_name=test_pipe_name) 6586 6587 # Then Grid search. 6588 if True: 6589 # Do Grid search. 6590 RDR.minimise_grid_search(inc=4, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6591 6592 # Then Minimise. 6593 if True: 6594 # Minimise 6595 RDR.opt_max_iterations = int(1e2) 6596 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min_ind', analysis_from='grid_setup_ind', list_glob_ini=list_glob_ini, force=True) 6597 6598 #print asd 6599 6600 # Plot statistics. 6601 # Try plot some minimisation correlations. 6602 if True: 6603 selections = [None, ':2,3'] 6604 for selection in selections: 6605 # Collect param values. 6606 analysis = 'min_ind' 6607 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6608 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6609 6610 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6611 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6612 corr_data = [fig1, fig2] 6613 6614 write_stats = True 6615 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6616 6617 # Open stat file. 6618 if write_stats: 6619 for i, corr_data_i in enumerate(corr_data): 6620 data, methods, glob_inis = corr_data[i] 6621 data_x, data_y = data 6622 method_x, method_y = methods 6623 glob_ini_x, glob_ini_y = glob_inis 6624 6625 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6626 6627 if selection == None: 6628 file_name = file_name_ini + '_all.txt' 6629 else: 6630 file_name = file_name_ini + '_sel.txt' 6631 path = RDR.results_dir 6632 data = extract_data(file=file_name, dir=path) 6633 6634 # Loop over the lines. 6635 for i, data_i in enumerate(data): 6636 print(i, data_i) 6637 6638 # Try plot some minimisation statistics. 6639 if True: 6640 # Collect param values. 6641 #selections = [None, ':2,3'] 6642 selections = [None, ':2,3'] 6643 for selection in selections: 6644 analysis = 'min_ind' 6645 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6646 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6647 6648 # Get param stats. 6649 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6650 6651 ## Plot R2eff stats 6652 write_stats = True 6653 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6654 6655 # Open stat file. 6656 if write_stats: 6657 if selection == None: 6658 file_name = '%s_stat_all.txt' % (analysis) 6659 else: 6660 file_name = '%s_stat_sel.txt' % (analysis) 6661 path = RDR.results_dir 6662 data = extract_data(file=file_name, dir=path) 6663 6664 # Loop over the lines. 6665 for i, data_i in enumerate(data): 6666 print(i, data_i) 6667 6668 6669 # Do minimisation clustered. 6670 if True: 6671 methods = ['FT', 'MDD'] 6672 # Now calculate R2eff. 6673 RDR.calc_r2eff(methods=methods, list_glob_ini=[128, 126]) 6674 6675 min_methods = [['FT'], ['MDD']] 6676 min_list_glob_ini = [[128], list(range(126, 130, 2))[::-1]] 6677 6678 #min_methods = [['FT']] 6679 #min_list_glob_ini = [[128]] 6680 selection = ':2,3' 6681 6682 for i, methods in enumerate(min_methods): 6683 list_glob_ini = min_list_glob_ini[i] 6684 6685 if True: 6686 # First get data. 6687 if True: 6688 # First load all data. 6689 RDR.calc_r2eff(methods=methods, list_glob_ini=list_glob_ini) 6690 6691 # Then select spins. 6692 if True: 6693 # Deselect all spins. 6694 RDR.deselect_all(methods=methods, model='setup', model_from=MODEL_R2EFF, analysis='grid_setup', analysis_from='int', list_glob_ini=list_glob_ini, force=True) 6695 6696 RDR.select_spin(spin_id=selection, methods=methods, model='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6697 6698 # Then preset values. 6699 if True: 6700 # Set k_AB for Grid search. 6701 RDR.value_set(methods=methods, val=1000., param='kex', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6702 RDR.value_set(methods=methods, val=0.95, param='pA', model=MODEL_CR72, model_from='setup', analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6703 6704 # Then set R20 6705 if True: 6706 # Set R20 from min R2eff in preparation for Grid search. 6707 RDR.r20_from_min_r2eff(methods=methods, model=MODEL_CR72, analysis='grid_setup', list_glob_ini=list_glob_ini, force=True) 6708 6709 # Check and print parameters. 6710 if True: 6711 # Print for pipe name 6712 method = methods[0] 6713 glob_ini = list_glob_ini[0] 6714 6715 test_pipe_name = RDR.name_pipe(method=method, model=MODEL_CR72, analysis='grid_setup', glob_ini=glob_ini) 6716 RDR.spin_display_params(pipe_name=test_pipe_name) 6717 6718 # Then Grid search. 6719 if True: 6720 # Do Grid search. 6721 RDR.minimise_grid_search(inc=200, verbosity=1, methods=methods, model=MODEL_CR72, analysis='grid', analysis_from='grid_setup', list_glob_ini=list_glob_ini, force=True) 6722 6723 # Then cluster spins. 6724 if True: 6725 RDR.cluster_spins(spin_id=selection, methods=methods, model=MODEL_CR72, analysis='grid', list_glob_ini=list_glob_ini, force=True) 6726 6727 # Then Minimise. 6728 if True: 6729 # Minimise 6730 RDR.opt_max_iterations = int(1e2) 6731 RDR.minimise_execute(methods=methods, model=MODEL_CR72, analysis='min', analysis_from='grid', list_glob_ini=list_glob_ini, force=False) 6732 6733 # Plot statistics. 6734 # Try plot some minimisation correlations. 6735 if True: 6736 selection = ':2,3' 6737 # Collect param values. 6738 analysis = 'min' 6739 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6740 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6741 6742 fig1 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 128]] 6743 fig2 = [[min_ft_sel, min_mdd_sel], ['FT', 'MDD'], [128, 126]] 6744 corr_data = [fig1, fig2] 6745 6746 write_stats = True 6747 RDR.plot_min_corr(corr_data=corr_data, show=False, write_stats=write_stats) 6748 6749 # Open stat file. 6750 if write_stats: 6751 for i, corr_data_i in enumerate(corr_data): 6752 data, methods, glob_inis = corr_data[i] 6753 data_x, data_y = data 6754 method_x, method_y = methods 6755 glob_ini_x, glob_ini_y = glob_inis 6756 6757 file_name_ini = '%s_%s_%s_%s_%s' % (analysis, method_x, glob_ini_x, method_y, glob_ini_y) 6758 6759 if selection == None: 6760 file_name = file_name_ini + '_all.txt' 6761 else: 6762 file_name = file_name_ini + '_sel.txt' 6763 path = RDR.results_dir 6764 data = extract_data(file=file_name, dir=path) 6765 6766 # Loop over the lines. 6767 for i, data_i in enumerate(data): 6768 print(i, data_i) 6769 6770 # Try plot some minimisation statistics. 6771 if True: 6772 # Collect param values. 6773 selections = [':2,3'] 6774 for selection in selections: 6775 analysis = 'min' 6776 min_ft_sel = RDR.col_min(method='FT', model=MODEL_CR72, analysis=analysis, list_glob_ini=[128], selection=selection) 6777 min_mdd_sel = RDR.col_min(method='MDD', model=MODEL_CR72, analysis=analysis, list_glob_ini=list(range(126, 130, 2))[::-1], selection=selection) 6778 6779 # Get param stats. 6780 min_stat_dic = RDR.get_min_stat_dic(list_r2eff_dics=[min_ft_sel, min_mdd_sel], list_glob_ini=[128, 126]) 6781 6782 ## Plot R2eff stats 6783 write_stats = True 6784 RDR.plot_min_stat(min_stat_dic=min_stat_dic, methods=['FT', 'MDD'], list_glob_ini=[128, 126, 6], show=False, write_stats=write_stats) 6785 6786 # Open stat file. 6787 if write_stats: 6788 if selection == None: 6789 file_name = '%s_stat_all.txt' % (analysis) 6790 else: 6791 file_name = '%s_stat_sel.txt' % (analysis) 6792 path = RDR.results_dir 6793 data = extract_data(file=file_name, dir=path) 6794 6795 # Loop over the lines. 6796 for i, data_i in enumerate(data): 6797 print(i, data_i)
6798 6799 6800
6801 - def test_r1rho_kjaergaard_auto(self):
6802 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 6803 6804 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 6805 6806 This uses the automatic analysis. 6807 6808 """ 6809 6810 # Cluster residues 6811 cluster_ids = [ 6812 ":13@N", 6813 ":15@N", 6814 ":16@N", 6815 ":25@N", 6816 ":26@N", 6817 ":28@N", 6818 ":39@N", 6819 ":40@N", 6820 ":41@N", 6821 ":43@N", 6822 ":44@N", 6823 ":45@N", 6824 ":49@N", 6825 ":52@N", 6826 ":53@N"] 6827 6828 # Load the data. 6829 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 6830 6831 # Test some of the sequence. 6832 self.assertEqual(len(cdp.mol), 1) 6833 self.assertEqual(cdp.mol[0].name, None) 6834 self.assertEqual(len(cdp.mol[0].res), 48) 6835 6836 # Test the chemical shift data. 6837 cs = [122.223, 122.162, 114.250, 125.852, 118.626, 117.449, 119.999, 122.610, 118.602, 118.291, 115.393, 6838 121.288, 117.448, 116.378, 116.316, 117.263, 122.211, 118.748, 118.103, 119.421, 119.317, 119.386, 117.279, 6839 122.103, 120.038, 116.698, 111.811, 118.639, 118.285, 121.318, 117.770, 119.948, 119.759, 118.314, 118.160, 6840 121.442, 118.714, 113.080, 125.706, 119.183, 120.966, 122.361, 126.675, 117.069, 120.875, 109.372, 119.811, 126.048] 6841 6842 i = 0 6843 for spin, spin_id in spin_loop(return_id=True): 6844 # Check the chemical shift. 6845 self.assertEqual(spin.chemical_shift, cs[i]) 6846 6847 # Increment the index. 6848 i += 1 6849 6850 # Initialize counter 6851 i = 0 6852 j = 0 6853 # Count instances of select/deselect 6854 for curspin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=False): 6855 if curspin.select == True: 6856 i += 1 6857 if curspin.select == False: 6858 j += 1 6859 6860 # Test number of selected/deselected spins. 6861 self.assertEqual(i, len(cluster_ids)) 6862 self.assertEqual(j, 48-len(cluster_ids)) 6863 6864 # Check the initial setup. 6865 self.assertEqual(cdp.mol[0].res[7].num, 13) 6866 self.assertEqual(cdp.mol[0].res[7].spin[0].kex, ds.guess[':13@N'][6]) 6867 self.assertEqual(cdp.mol[0].res[7].spin[0].ri_data['R1'], ds.ref[':13@N'][2]) 6868 6869 self.assertEqual(cdp.mol[0].res[9].num, 15) 6870 self.assertEqual(cdp.mol[0].res[9].spin[0].kex, ds.guess[':15@N'][6]) 6871 self.assertEqual(cdp.mol[0].res[9].spin[0].ri_data['R1'], ds.ref[':15@N'][2]) 6872 6873 self.assertEqual(cdp.mol[0].res[10].num, 16) 6874 self.assertEqual(cdp.mol[0].res[10].spin[0].kex, ds.guess[':16@N'][6]) 6875 self.assert_(hasattr(cdp.mol[0].res[10].spin[0], 'ri_data')) 6876 6877 self.assertEqual(cdp.mol[0].res[16].num, 25) 6878 self.assertEqual(cdp.mol[0].res[16].spin[0].kex, ds.guess[':25@N'][6]) 6879 self.assert_(hasattr(cdp.mol[0].res[16].spin[0], 'ri_data')) 6880 6881 self.assertEqual(cdp.mol[0].res[17].num, 26) 6882 self.assertEqual(cdp.mol[0].res[17].spin[0].kex, ds.guess[':26@N'][6]) 6883 self.assert_(hasattr(cdp.mol[0].res[17].spin[0], 'ri_data')) 6884 6885 self.assertEqual(cdp.mol[0].res[19].num, 28) 6886 self.assertEqual(cdp.mol[0].res[19].spin[0].kex, ds.guess[':28@N'][6]) 6887 self.assert_(hasattr(cdp.mol[0].res[19].spin[0], 'ri_data')) 6888 6889 self.assertEqual(cdp.mol[0].res[29].num, 39) 6890 self.assertEqual(cdp.mol[0].res[29].spin[0].kex, ds.guess[':39@N'][6]) 6891 self.assert_(hasattr(cdp.mol[0].res[29].spin[0], 'ri_data')) 6892 6893 self.assertEqual(cdp.mol[0].res[30].num, 40) 6894 self.assertEqual(cdp.mol[0].res[30].spin[0].kex, ds.guess[':40@N'][6]) 6895 self.assert_(hasattr(cdp.mol[0].res[30].spin[0], 'ri_data')) 6896 6897 self.assertEqual(cdp.mol[0].res[31].num, 41) 6898 self.assertEqual(cdp.mol[0].res[31].spin[0].kex, ds.guess[':41@N'][6]) 6899 self.assert_(hasattr(cdp.mol[0].res[31].spin[0], 'ri_data')) 6900 6901 self.assertEqual(cdp.mol[0].res[33].num, 43) 6902 self.assertEqual(cdp.mol[0].res[33].spin[0].kex, ds.guess[':43@N'][6]) 6903 self.assert_(hasattr(cdp.mol[0].res[33].spin[0], 'ri_data')) 6904 6905 self.assertEqual(cdp.mol[0].res[34].num, 44) 6906 self.assertEqual(cdp.mol[0].res[34].spin[0].kex, ds.guess[':44@N'][6]) 6907 self.assert_(hasattr(cdp.mol[0].res[34].spin[0], 'ri_data')) 6908 6909 self.assertEqual(cdp.mol[0].res[35].num, 45) 6910 self.assertEqual(cdp.mol[0].res[35].spin[0].kex, ds.guess[':45@N'][6]) 6911 self.assert_(hasattr(cdp.mol[0].res[35].spin[0], 'ri_data')) 6912 6913 self.assertEqual(cdp.mol[0].res[38].num, 49) 6914 self.assertEqual(cdp.mol[0].res[38].spin[0].kex, ds.guess[':49@N'][6]) 6915 self.assert_(hasattr(cdp.mol[0].res[38].spin[0], 'ri_data')) 6916 6917 self.assertEqual(cdp.mol[0].res[41].num, 52) 6918 self.assertEqual(cdp.mol[0].res[41].spin[0].kex, ds.guess[':52@N'][6]) 6919 self.assert_(hasattr(cdp.mol[0].res[41].spin[0], 'ri_data')) 6920 6921 self.assertEqual(cdp.mol[0].res[42].num, 53) 6922 self.assertEqual(cdp.mol[0].res[42].spin[0].kex, ds.guess[':53@N'][6]) 6923 self.assert_(hasattr(cdp.mol[0].res[42].spin[0], 'ri_data')) 6924 6925 # The dispersion models. 6926 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 6927 6928 # The grid search size (the number of increments per dimension). 6929 GRID_INC = 4 6930 6931 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 6932 MC_NUM = 3 6933 6934 # Model selection technique. 6935 MODSEL = 'AIC' 6936 6937 # Execute the auto-analysis (fast). 6938 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 6939 OPT_FUNC_TOL = 1e-1 6940 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 6941 OPT_MAX_ITERATIONS = 1000 6942 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 6943 6944 result_dir_name = ds.tmpdir 6945 6946 # Make all spins free 6947 for curspin in cluster_ids: 6948 self.interpreter.relax_disp.cluster('free spins', curspin) 6949 # Shut them down 6950 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 6951 6952 # Select only a subset of spins for global fitting 6953 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 6954 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 6955 6956 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 6957 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 6958 6959 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 6960 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 6961 6962 # Run the analysis. 6963 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 6964 6965 # Check the kex value of residue 52 6966 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 6967 6968 # Print results for each model. 6969 print("\n\n################") 6970 print("Printing results") 6971 print("################\n") 6972 for model in MODELS: 6973 # Skip R2eff model. 6974 if model == MODEL_R2EFF: 6975 continue 6976 6977 # Switch to pipe. 6978 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 6979 print("\nModel: %s" % (model)) 6980 6981 # Loop over the spins. 6982 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 6983 # Generate spin string. 6984 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 6985 6986 # Loop over the parameters. 6987 print("Optimised parameters for spin: %s" % (spin_string)) 6988 for param in cur_spin.params + ['chi2']: 6989 # Get the value. 6990 if param in ['r1', 'r2']: 6991 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 6992 # Generate the R20 key. 6993 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 6994 6995 # Get the value. 6996 value = getattr(cur_spin, param)[r20_key] 6997 6998 # Print value. 6999 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7000 7001 # For all other parameters. 7002 else: 7003 # Get the value. 7004 value = getattr(cur_spin, param) 7005 7006 # Print value. 7007 print("%-10s %-6s %-6s %3.3f" % ("Parameter:", param, "Value:", value)) 7008 7009 # Print the final pipe. 7010 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % ('final')) 7011 print("\nFinal pipe")
7012 7013
7015 """Check of plot_disp_curves() function, after optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'R2eff' model. 7016 7017 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7018 7019 This uses the automatic analysis. 7020 7021 """ 7022 7023 # Cluster residues 7024 cluster_ids = [ 7025 ":52@N"] 7026 7027 # Load the data. 7028 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids) 7029 7030 # The dispersion models. 7031 MODELS = [MODEL_R2EFF] 7032 7033 # The grid search size (the number of increments per dimension). 7034 GRID_INC = 4 7035 7036 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7037 MC_NUM = 3 7038 7039 # Model selection technique. 7040 MODSEL = 'AIC' 7041 7042 # Execute the auto-analysis (fast). 7043 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7044 OPT_FUNC_TOL = 1e-1 7045 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7046 OPT_MAX_ITERATIONS = 1000 7047 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7048 7049 result_dir_name = ds.tmpdir 7050 7051 # Make all spins free 7052 for curspin in cluster_ids: 7053 self.interpreter.relax_disp.cluster('free spins', curspin) 7054 # Shut them down 7055 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7056 7057 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7058 7059 # Run the analysis. 7060 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 7061 7062 # Check the graphs produced. 7063 graph_comb = [ 7064 [Y_AXIS_R2_EFF, X_AXIS_DISP, INTERPOLATE_DISP], 7065 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_DISP], 7066 [Y_AXIS_R2_R1RHO, X_AXIS_W_EFF, INTERPOLATE_DISP], 7067 [Y_AXIS_R2_EFF, X_AXIS_THETA, INTERPOLATE_OFFSET] 7068 ] 7069 7070 # Define expected folder names. 7071 result_folders = MODELS 7072 7073 # Assign spin_id. 7074 spin_id = ':52@N' 7075 7076 # Loop over result folders. 7077 for result_folder in result_folders: 7078 # Skip the model R2eff, which does not produce graphs. 7079 if result_folder == MODEL_R2EFF: 7080 continue 7081 7082 # Loop over graphs. 7083 for y_axis, x_axis, interpolate in graph_comb: 7084 # Determine file name: 7085 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7086 7087 # Make the file name. 7088 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7089 7090 # Get the file path. 7091 file_path = get_file_path(file_name, result_dir_name+sep+result_folder) 7092 7093 print("Testing file access to graph: %s"%file_path) 7094 self.assert_(access(file_path, F_OK)) 7095 7096 # Start testing all possible combinations of graphs. 7097 y_axis_types = [Y_AXIS_R2_EFF, Y_AXIS_R2_R1RHO] 7098 x_axis_types = [X_AXIS_DISP, X_AXIS_THETA, X_AXIS_W_EFF] 7099 interpolate_types = [INTERPOLATE_DISP, INTERPOLATE_OFFSET] 7100 7101 result_dir_name = ds.tmpdir 7102 7103 # Loop through all possible combinations of y_axis, x_axis and interpolation. 7104 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep+'check_graphs' 7105 7106 for result_folder in result_folders: 7107 # Skip the model R2eff, which does not produce graphs. 7108 if result_folder == MODEL_R2EFF: 7109 continue 7110 7111 for y_axis in y_axis_types: 7112 for x_axis in x_axis_types: 7113 for interpolate in interpolate_types: 7114 # Determine file name: 7115 file_name_ini = return_grace_file_name_ini(y_axis=y_axis, x_axis=x_axis, interpolate=interpolate) 7116 7117 # Make the file name. 7118 file_name = "%s%s.agr" % (file_name_ini, spin_id.replace('#', '_').replace(':', '_').replace('@', '_')) 7119 7120 # Write the curves. 7121 dir = result_dir_name+sep+result_folder 7122 print("Plotting combination of %s, %s, %s"%(y_axis, x_axis, interpolate)) 7123 self.interpreter.relax_disp.plot_disp_curves(dir=dir, y_axis=y_axis, x_axis=x_axis, interpolate=interpolate, force=True) 7124 7125 # Get the file path. 7126 file_path = get_file_path(file_name, dir) 7127 7128 # Test the plot file exists. 7129 print("Testing file access to graph: %s"%file_path) 7130 self.assert_(access(file_path, F_OK)) 7131 7132 # Now open, and compare content, line by line. 7133 file_prod = open(file_path) 7134 lines_prod = file_prod.readlines() 7135 file_prod.close() 7136 7137 # Define file to compare against. 7138 dir_comp = data_path+sep+result_folder 7139 file_path_comp = get_file_path(file_name, dir_comp) 7140 file_comp = open(file_path_comp) 7141 lines_comp = file_comp.readlines() 7142 file_comp.close() 7143 7144 # Assert number of lines is equal. 7145 self.assertEqual(len(lines_prod), len(lines_comp)) 7146 for j in range(len(lines_prod)): 7147 # Make the string test 7148 first_char = lines_prod[j][0] 7149 if first_char in ["@", "&"]: 7150 self.assertEqual(lines_prod[j], lines_comp[j]) 7151 else: 7152 # Split string in x, y, error. 7153 # The error would change per run. 7154 x_prod, y_prod, y_prod_err = lines_prod[j].split() 7155 x_comp, y_comp, y_comp_err = lines_comp[j].split() 7156 self.assertAlmostEqual(float(x_prod), float(x_comp)) 7157 self.assertAlmostEqual(float(y_prod), float(y_comp))
7158 7159
7161 """Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 7162 7163 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 7164 7165 This uses the automatic analysis, with missing loading R1. 7166 7167 """ 7168 7169 # Cluster residues 7170 cluster_ids = [ 7171 ":13@N", 7172 ":15@N", 7173 ":16@N", 7174 ":25@N", 7175 ":26@N", 7176 ":28@N", 7177 ":39@N", 7178 ":40@N", 7179 ":41@N", 7180 ":43@N", 7181 ":44@N", 7182 ":45@N", 7183 ":49@N", 7184 ":52@N", 7185 ":53@N"] 7186 7187 # Load the data. 7188 self.setup_r1rho_kjaergaard(cluster_ids=cluster_ids, read_R1=False) 7189 7190 # The dispersion models. 7191 MODELS = [MODEL_R2EFF, MODEL_NOREX, MODEL_DPL94, MODEL_TP02, MODEL_TAP03, MODEL_MP05, MODEL_NS_R1RHO_2SITE] 7192 7193 # The grid search size (the number of increments per dimension). 7194 GRID_INC = None 7195 7196 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7197 MC_NUM = 3 7198 7199 # Model selection technique. 7200 MODSEL = 'AIC' 7201 7202 # Execute the auto-analysis (fast). 7203 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7204 OPT_FUNC_TOL = 1e-25 7205 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7206 OPT_MAX_ITERATIONS = 10000000 7207 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7208 7209 result_dir_name = ds.tmpdir 7210 7211 # Make all spins free 7212 for curspin in cluster_ids: 7213 self.interpreter.relax_disp.cluster('free spins', curspin) 7214 # Shut them down 7215 self.interpreter.deselect.spin(spin_id=curspin, change_all=False) 7216 7217 # Select only a subset of spins for global fitting 7218 #self.interpreter.select.spin(spin_id=':41@N', change_all=False) 7219 #self.interpreter.relax_disp.cluster('model_cluster', ':41@N') 7220 7221 #self.interpreter.select.spin(spin_id=':40@N', change_all=False) 7222 #self.interpreter.relax_disp.cluster('model_cluster', ':40@N') 7223 7224 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 7225 #self.interpreter.relax_disp.cluster('model_cluster', ':52@N') 7226 7227 # Point to directory with R2eff values, with 2000 MC simulations. 7228 prev_data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' +sep+ "check_graphs" +sep+ "mc_2000" 7229 7230 r1_fit = True 7231 7232 # Run the analysis. 7233 relax_disp.Relax_disp(pipe_name=ds.pipe_name, pipe_bundle=ds.pipe_bundle, results_dir=result_dir_name, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, pre_run_dir=prev_data_path, r1_fit=r1_fit) 7234 7235 # Verify the data. 7236 self.verify_r1rho_kjaergaard_missing_r1(models=MODELS, result_dir_name=result_dir_name, r2eff_estimate='MC2000')
7237 7238
7239 - def test_r2eff_read(self):
7240 """Test the operation of the relax_disp.r2eff_read user function.""" 7241 7242 # The path to the data files. 7243 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Hansen'+sep+'800_MHz' 7244 7245 # Read the sequence data. 7246 self.interpreter.sequence.read(file='66.667.in', dir=data_path, res_num_col=1) 7247 7248 # The ID. 7249 id = 'test' 7250 7251 # Set up the metadata. 7252 self.interpreter.spectrometer.frequency(id=id, frq=800e6) 7253 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7254 7255 # Try reading the file. 7256 self.interpreter.relax_disp.r2eff_read(id=id, file='66.667.in', dir=data_path, disp_frq=66.667, res_num_col=1, data_col=2, error_col=3) 7257 7258 # Check the global data. 7259 data = [ 7260 ['cpmg_frqs', {'test': 66.667}], 7261 ['cpmg_frqs_list', [66.667]], 7262 ['dispersion_points', 1], 7263 ['exp_type', {'test': 'SQ CPMG'}], 7264 ['exp_type_list', ['SQ CPMG']], 7265 ['spectrometer_frq', {'test': 800000000.0}], 7266 ['spectrometer_frq_count', 1], 7267 ['spectrometer_frq_list', [800000000.0]], 7268 ['spectrum_ids', ['test']] 7269 ] 7270 for name, value in data: 7271 # Does it exist? 7272 self.assert_(hasattr(cdp, name)) 7273 7274 # Check the object. 7275 obj = getattr(cdp, name) 7276 self.assertEqual(obj, value) 7277 7278 # Check the spin data. 7279 data = [ 7280 [1, 2.3035747e+04, 8.5467725e+01], 7281 [2, 9.9629762e+04, 2.8322033e+02], 7282 [3, 9.5663137e+04, 2.8632929e+02], 7283 [4, 1.7089893e+05, 3.1089428e+02], 7284 [5, 4.7323876e+04, 1.0084269e+02], 7285 [6, 2.0199122e+04, 1.0135220e+02], 7286 [7, 1.6655488e+05, 3.1609061e+02], 7287 [8, 9.0061074e+04, 1.9176585e+02], 7288 [10, 8.4726204e+04, 2.8898155e+02], 7289 [11, 1.5050233e+05, 4.3138029e+02], 7290 [12, 9.2998531e+04, 3.0440191e+02], 7291 [13, 1.6343507e+05, 3.3144097e+02], 7292 [14, 1.0137301e+05, 3.7314642e+02], 7293 [15, 8.3407837e+04, 1.6546473e+02], 7294 [16, 1.3819126e+05, 3.3388517e+02], 7295 [17, 1.1010490e+05, 3.5639222e+02], 7296 [18, 9.4324035e+04, 3.2343585e+02], 7297 [19, 1.1135179e+05, 3.0706671e+02], 7298 [20, 7.6339410e+04, 1.7377460e+02], 7299 [21, 6.2008453e+04, 1.7327150e+02], 7300 [22, 1.0590404e+05, 2.4814635e+02], 7301 [23, 1.0630198e+05, 2.3601100e+02], 7302 [24, 7.2996320e+04, 1.4952465e+02], 7303 [25, 9.5486742e+04, 2.7080766e+02], 7304 [26, 5.8067989e+04, 1.6820462e+02], 7305 [27, -1.7168510e+04, 2.2519560e+02], 7306 [28, 1.6891473e+05, 2.3497525e+02], 7307 [29, 9.4038555e+04, 2.0357593e+02], 7308 [30, 2.1386951e+04, 2.2153532e+02], 7309 [31, 9.3982899e+04, 2.0937056e+02], 7310 [32, 8.6097484e+04, 2.3868467e+02], 7311 [33, 1.0194337e+05, 2.7370704e+02], 7312 [34, 8.5683111e+04, 2.0838076e+02], 7313 [35, 8.6985768e+04, 2.0889310e+02], 7314 [36, 8.6011237e+04, 1.7498390e+02], 7315 [37, 1.0984097e+05, 2.7622998e+02], 7316 [38, 8.7017879e+04, 2.6547994e+02], 7317 [39, 9.1682649e+04, 5.2777676e+02], 7318 [40, 7.6370440e+04, 1.9873214e+02], 7319 [41, 9.1393531e+04, 2.4483824e+02], 7320 [42, 1.1017111e+05, 2.8020699e+02], 7321 [43, 9.4552366e+04, 3.4394150e+02], 7322 [44, 1.2858281e+05, 6.8449252e+02], 7323 [45, 7.4583525e+04, 1.9544210e+02], 7324 [46, 9.2087490e+04, 2.0491066e+02], 7325 [47, 9.7507255e+04, 2.5162839e+02], 7326 [48, 1.0033842e+05, 2.7566430e+02], 7327 [49, 1.3048305e+05, 2.6797466e+02], 7328 [50, 1.0546796e+05, 1.9304384e+02], 7329 [51, 9.3099697e+04, 2.0773311e+02], 7330 [52, 4.6863758e+04, 1.3169068e+02], 7331 [53, 6.1055806e+04, 1.5448477e+02], 7332 [55, 6.8629994e+04, 1.6868673e+02], 7333 [56, 1.1005552e+05, 2.1940465e+02], 7334 [57, 1.0572760e+05, 1.9768486e+02], 7335 [58, 1.1176950e+05, 3.0009610e+02], 7336 [59, 9.8758603e+04, 3.3803895e+02], 7337 [60, 9.9517201e+04, 3.5137994e+02], 7338 [61, 5.4357946e+04, 2.5896579e+02], 7339 [62, 1.0899978e+05, 2.8720371e+02], 7340 [63, 8.4549759e+04, 4.1401837e+02], 7341 [64, 5.5014550e+04, 2.1135781e+02], 7342 [65, 8.0569666e+04, 2.3249709e+02], 7343 [66, 1.2936610e+05, 3.5218725e+02], 7344 [67, 3.6438010e+04, 8.7924003e+01], 7345 [70, 3.8763157e+04, 1.3325040e+02], 7346 [71, 8.5711411e+04, 2.9316183e+02], 7347 [72, 3.3211541e+04, 1.2182123e+02], 7348 [73, 3.2070576e+04, 1.2305430e+02] 7349 ] 7350 for res_num, value, error in data: 7351 # Get the spin. 7352 spin = return_spin(spin_id=":%s"%res_num) 7353 7354 # Check the values. 7355 self.assertEqual(spin.r2eff['sq_cpmg_800.00000000_0.000_66.667'], value) 7356 self.assertEqual(spin.r2eff_err['sq_cpmg_800.00000000_0.000_66.667'], error)
7357 7358
7359 - def test_r2eff_read_spin(self):
7360 """Test the operation of the relax_disp.r2eff_read_spin user function.""" 7361 7362 # The path to the data files. 7363 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Korzhnev_et_al_2005' 7364 7365 # Generate the sequence. 7366 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='H') 7367 self.interpreter.spin.create(res_name='Asp', res_num=9, spin_name='N') 7368 self.interpreter.spin.isotope('1H', spin_id='@H') 7369 self.interpreter.spin.isotope('15N', spin_id='@N') 7370 7371 # Build the experiment IDs. 7372 H_disp_points = [67.0, 133.0, 267.0, 400.0, 533.0, 667.0, 800.0, 933.0, 1067.0, 1600.0, 2133.0, 2667.0] 7373 N_disp_points = [50.0, 100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 400.0, 500.0, 600.0, 700.0, 800.0, 900.0, 1000.0] 7374 ids = [] 7375 for value in H_disp_points: 7376 ids.append('1H_CPMG_%s' % value) 7377 for value in N_disp_points: 7378 ids.append('15N_CPMG_%s' % value) 7379 print("\n\nThe experiment IDs are %s." % ids) 7380 7381 # Set up the metadata for the experiments. 7382 for id in ids: 7383 self.interpreter.spectrometer.frequency(id=id, frq=500e6) 7384 self.interpreter.relax_disp.exp_type(spectrum_id=id, exp_type='SQ CPMG') 7385 for value in H_disp_points: 7386 self.interpreter.relax_disp.cpmg_setup(spectrum_id='1H_CPMG_%s' % value, cpmg_frq=value) 7387 for value in N_disp_points: 7388 self.interpreter.relax_disp.cpmg_setup(spectrum_id='15N_CPMG_%s' % value, cpmg_frq=value) 7389 7390 # Loop over the experiments. 7391 for id, file, spin_id in [['1H_CPMG', 'hs_500.res', ':9@H'], ['15N_CPMG', 'ns_500.res', ':9@N']]: 7392 # Try reading the file. 7393 self.interpreter.relax_disp.r2eff_read_spin(id=id, file=file, dir=data_path, spin_id=spin_id, disp_point_col=1, data_col=2, error_col=3) 7394 7395 # Check the global data. 7396 data = [ 7397 ['cpmg_frqs', {'1H_CPMG_667.0': 667.0, '1H_CPMG_1067.0': 1067.0, '15N_CPMG_350.0': 350.0, '1H_CPMG_933.0': 933.0, '15N_CPMG_50.0': 50.0, '15N_CPMG_100.0': 100.0, '1H_CPMG_400.0': 400.0, '1H_CPMG_533.0': 533.0, '1H_CPMG_800.0': 800.0, '15N_CPMG_900.0': 900.0, '15N_CPMG_150.0': 150.0, '15N_CPMG_800.0': 800.0, '1H_CPMG_267.0': 267.0, '1H_CPMG_2667.0': 2667.0, '15N_CPMG_300.0': 300.0, '1H_CPMG_133.0': 133.0, '15N_CPMG_700.0': 700.0, '1H_CPMG_67.0': 67.0, '15N_CPMG_400.0': 400.0, '15N_CPMG_250.0': 250.0, '1H_CPMG_2133.0': 2133.0, '1H_CPMG_1600.0': 1600.0, '15N_CPMG_200.0': 200.0, '15N_CPMG_1000.0': 1000.0, '15N_CPMG_500.0': 500.0, '15N_CPMG_600.0': 600.0}], 7398 ['cpmg_frqs_list', [50.0, 67.0, 100.0, 133.0, 150.0, 200.0, 250.0, 267.0, 300.0, 350.0, 400.0, 500.0, 533.0, 600.0, 667.0, 700.0, 800.0, 900.0, 933.0, 1000.0, 1067.0, 1600.0, 2133.0, 2667.0]], 7399 ['dispersion_points', 24], 7400 ['exp_type', {'1H_CPMG_667.0': 'SQ CPMG', '1H_CPMG_1067.0': 'SQ CPMG', '15N_CPMG_350.0': 'SQ CPMG', '1H_CPMG_933.0': 'SQ CPMG', '15N_CPMG_50.0': 'SQ CPMG', '15N_CPMG_100.0': 'SQ CPMG', '1H_CPMG_400.0': 'SQ CPMG', '1H_CPMG_533.0': 'SQ CPMG', '1H_CPMG_800.0': 'SQ CPMG', '15N_CPMG_900.0': 'SQ CPMG', '15N_CPMG_150.0': 'SQ CPMG', '15N_CPMG_800.0': 'SQ CPMG', '1H_CPMG_267.0': 'SQ CPMG', '1H_CPMG_2667.0': 'SQ CPMG', '15N_CPMG_300.0': 'SQ CPMG', '1H_CPMG_133.0': 'SQ CPMG', '15N_CPMG_700.0': 'SQ CPMG', '1H_CPMG_67.0': 'SQ CPMG', '15N_CPMG_400.0': 'SQ CPMG', '15N_CPMG_250.0': 'SQ CPMG', '1H_CPMG_2133.0': 'SQ CPMG', '1H_CPMG_1600.0': 'SQ CPMG', '15N_CPMG_200.0': 'SQ CPMG', '15N_CPMG_1000.0': 'SQ CPMG', '15N_CPMG_500.0': 'SQ CPMG', '15N_CPMG_600.0': 'SQ CPMG'}], 7401 ['exp_type_list', ['SQ CPMG']], 7402 ['spectrometer_frq', {'1H_CPMG_667.0': 500000000.0, '1H_CPMG_1067.0': 500000000.0, '15N_CPMG_350.0': 500000000.0, '1H_CPMG_933.0': 500000000.0, '15N_CPMG_50.0': 500000000.0, '15N_CPMG_100.0': 500000000.0, '1H_CPMG_400.0': 500000000.0, '1H_CPMG_533.0': 500000000.0, '1H_CPMG_800.0': 500000000.0, '15N_CPMG_900.0': 500000000.0, '15N_CPMG_150.0': 500000000.0, '15N_CPMG_800.0': 500000000.0, '1H_CPMG_267.0': 500000000.0, '1H_CPMG_2667.0': 500000000.0, '15N_CPMG_300.0': 500000000.0, '1H_CPMG_133.0': 500000000.0, '15N_CPMG_700.0': 500000000.0, '1H_CPMG_67.0': 500000000.0, '15N_CPMG_400.0': 500000000.0, '15N_CPMG_250.0': 500000000.0, '1H_CPMG_2133.0': 500000000.0, '1H_CPMG_1600.0': 500000000.0, '15N_CPMG_200.0': 500000000.0, '15N_CPMG_1000.0': 500000000.0, '15N_CPMG_500.0': 500000000.0, '15N_CPMG_600.0': 500000000.0}], 7403 ['spectrometer_frq_count', 1], 7404 ['spectrometer_frq_list', [500000000.0]], 7405 ['spectrum_ids', ['1H_CPMG_67.0', '1H_CPMG_133.0', '1H_CPMG_267.0', '1H_CPMG_400.0', '1H_CPMG_533.0', '1H_CPMG_667.0', '1H_CPMG_800.0', '1H_CPMG_933.0', '1H_CPMG_1067.0', '1H_CPMG_1600.0', '1H_CPMG_2133.0', '1H_CPMG_2667.0', '15N_CPMG_50.0', '15N_CPMG_100.0', '15N_CPMG_150.0', '15N_CPMG_200.0', '15N_CPMG_250.0', '15N_CPMG_300.0', '15N_CPMG_350.0', '15N_CPMG_400.0', '15N_CPMG_500.0', '15N_CPMG_600.0', '15N_CPMG_700.0', '15N_CPMG_800.0', '15N_CPMG_900.0', '15N_CPMG_1000.0']] 7406 ] 7407 for name, value in data: 7408 # Does it exist? 7409 self.assert_(hasattr(cdp, name)) 7410 7411 # Check the object. 7412 obj = getattr(cdp, name) 7413 if not isinstance(data, dict): 7414 self.assertEqual(obj, value) 7415 7416 # Check the global dictionary data. 7417 else: 7418 for id in ids: 7419 self.assertEqual(obj[id], value[id]) 7420 7421 # Check the spin data. 7422 h_data = [ 7423 [ 67.0, 21.47924, 0.42958], 7424 [ 133.0, 16.73898, 0.33478], 7425 [ 267.0, 9.97357, 0.19947], 7426 [ 400.0, 8.23877, 0.24737], 7427 [ 533.0, 7.59290, 0.24263], 7428 [ 667.0, 7.45843, 0.24165], 7429 [ 800.0, 7.11222, 0.23915], 7430 [ 933.0, 7.40880, 0.24129], 7431 [1067.0, 6.55191, 0.16629], 7432 [1600.0, 6.72177, 0.23637], 7433 [2133.0, 7.09629, 0.23904], 7434 [2667.0, 7.14675, 0.23940] 7435 ] 7436 for disp_point, value, error in h_data: 7437 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7438 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff[id], value) 7439 self.assertEqual(cdp.mol[0].res[0].spin[0].r2eff_err[id], error) 7440 n_data = [ 7441 [ 50.0, 27.15767, 0.54315], 7442 [ 100.0, 26.55781, 0.53116], 7443 [ 150.0, 24.73462, 0.49469], 7444 [ 200.0, 20.98617, 0.41972], 7445 [ 250.0, 17.82442, 0.35649], 7446 [ 300.0, 15.55352, 0.31107], 7447 [ 350.0, 13.78958, 0.27579], 7448 [ 400.0, 12.48334, 0.24967], 7449 [ 500.0, 11.55724, 0.23114], 7450 [ 600.0, 10.53874, 0.21077], 7451 [ 700.0, 10.07395, 0.20148], 7452 [ 800.0, 9.62952, 0.19259], 7453 [ 900.0, 9.49994, 0.19000], 7454 [1000.0, 8.71350, 0.17427] 7455 ] 7456 for disp_point, value, error in n_data: 7457 id = 'sq_cpmg_500.00000000_0.000_%.3f' % disp_point 7458 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff[id], value) 7459 self.assertEqual(cdp.mol[0].res[0].spin[1].r2eff_err[id], error)
7460 7461
7462 - def test_r2eff_fit_fixed_time(self):
7463 """Test the relaxation dispersion 'R2eff' model for fixed time data in the auto-analysis.""" 7464 7465 # Execute the script. 7466 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r2eff_calc.py')
7467 7468
7469 - def test_read_r2eff(self):
7470 """Test the reading of a file containing r2eff values.""" 7471 7472 # Create the sequence data, and name the spins. 7473 self.interpreter.residue.create(1, 'Gly') 7474 self.interpreter.residue.create(2, 'Gly') 7475 self.interpreter.residue.create(3, 'Gly') 7476 7477 # Read the file. 7478 self.interpreter.relax_data.read(ri_id='R2eff.600', ri_type='R2eff', frq=600*1e6, file='r2eff.out', dir=status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'r2eff', res_num_col=1, res_name_col=2, data_col=3, error_col=4) 7479 7480 # Test the data. 7481 self.assertEqual(cdp.mol[0].res[0].spin[0].ri_data['R2eff.600'], 15.000) 7482 self.assertEqual(cdp.mol[0].res[1].spin[0].ri_data['R2eff.600'], 4.2003) 7483 self.assertEqual(cdp.mol[0].res[2].spin[0].ri_data['R2eff.600'], 7.2385)
7484 7485
7487 """Test speeding up grid search. Support requst sr #3151 U{https://gna.org/support/index.php?3151}. 7488 7489 User function to set the R20 parameters in the default grid search using the minimum R2eff value. 7490 7491 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7492 'SOD1-WT' CPMG data to the CR72 dispersion model. 7493 7494 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7495 Data is for experiment at 25 degree Celcius. 7496 """ 7497 7498 # Base data setup. 7499 pipe_name = 'base pipe' 7500 pipe_type = 'relax_disp' 7501 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7502 select_spin_index = list(range(0, 1)) 7503 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7504 7505 # Generate r20 key. 7506 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7507 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7508 7509 ## Now prepare for MODEL calculation. 7510 MODEL = "CR72" 7511 7512 # Change pipe. 7513 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7514 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7515 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7516 7517 # Then select model. 7518 self.interpreter.relax_disp.select_model(model=MODEL) 7519 7520 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7521 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7522 7523 # Test result, for normal run. 7524 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7525 # Get the spin_params. 7526 spin_params = spin.params 7527 7528 # Defined fixed values for testing. 7529 if spin_id == ":10@N": 7530 self.assertEqual(spin.r2[r20_key_600], 20.282732526087106) 7531 self.assertEqual(spin.r2[r20_key_500], 18.475299724356649) 7532 7533 # Print out. 7534 print("r2_600=%2.2f r2_500=%2.2f spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin_id, resi, resn)) 7535 7536 # Testing the r2 values for the different fields are not the same. 7537 self.assert_(spin.r2[r20_key_600] != spin.r2[r20_key_500]) 7538 7539 # Test values are larger than 0. 7540 self.assert_(spin.r2[r20_key_600] > 0.0) 7541 self.assert_(spin.r2[r20_key_500] > 0.0) 7542 7543 # Loop over the experiment settings. 7544 r2eff_600 = [] 7545 r2eff_500 = [] 7546 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 7547 # Create the data key. 7548 data_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 7549 7550 # Extract the r2 eff data. 7551 r2eff = spin.r2eff[data_key] 7552 if frq == 599.8908617*1E6: 7553 r2eff_600.append(r2eff) 7554 elif frq == 499.862139*1E6: 7555 r2eff_500.append(r2eff) 7556 7557 # Sort values. 7558 r2eff_600.sort() 7559 r2eff_500.sort() 7560 7561 # Test values again. 7562 print("For r20 600MHz min r2eff=%3.3f."%(min(r2eff_600))) 7563 print(r2eff_600) 7564 self.assertEqual(spin.r2[r20_key_600], min(r2eff_600)) 7565 print("") 7566 7567 print("For r20 500MHz min r2eff=%3.3f."%(min(r2eff_500))) 7568 print(r2eff_500) 7569 self.assertEqual(spin.r2[r20_key_500], min(r2eff_500)) 7570 print("") 7571 7572 print("###########################################") 7573 print("Trying GRID SEARCH for minimum R2eff values") 7574 7575 ### Test just the Grid search. 7576 GRID_INC = 5 7577 7578 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7579 7580 ### Then test the value.set function. 7581 # Change pipe. 7582 pipe_name_MODEL = "%s_%s_2"%(pipe_name, MODEL) 7583 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7584 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7585 7586 # Then select model. 7587 self.interpreter.relax_disp.select_model(model=MODEL) 7588 7589 # Then set the standard parameter values. 7590 for param in spin_params: 7591 print("Setting standard parameter for param: %s"%param) 7592 self.interpreter.value.set(param=param, index=None) 7593 7594 # Test result, for normal run. 7595 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7596 # Print out. 7597 print("r2_600=%2.2f r2_500=%2.2f pA=%2.2f, dw=%2.2f, kex=%2.2f, spin_id=%s resi=%i resn=%s"%(spin.r2[r20_key_600], spin.r2[r20_key_500], spin.pA, spin.dw, spin.kex, spin_id, resi, resn)) 7598 7599 # Testing the r2 values. 7600 self.assertEqual(spin.r2[r20_key_600], 10.00) 7601 self.assertEqual(spin.r2[r20_key_500], 10.00) 7602 self.assertEqual(spin.pA, 0.9) 7603 self.assertEqual(spin.dw, 1.0) 7604 self.assertEqual(spin.kex, 1000.0) 7605 7606 print("###########################################") 7607 print("Trying GRID SEARCH for standard R2eff values") 7608 7609 ### Test just the Grid search. 7610 GRID_INC = 5 7611 7612 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7613 7614 ### Run auto_analysis. 7615 # The grid search size (the number of increments per dimension). 7616 GRID_INC = 5 7617 7618 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 7619 MC_NUM = 3 7620 7621 # Model selection technique. 7622 MODSEL = 'AIC' 7623 7624 # Execute the auto-analysis (fast). 7625 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7626 OPT_FUNC_TOL = 1e-1 7627 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 7628 OPT_MAX_ITERATIONS = 1000 7629 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 7630 7631 # Run the analysis. 7632 relax_disp.Relax_disp(pipe_name=pipe_name_r2eff, results_dir=ds.tmpdir, models=[MODEL], grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL, set_grid_r20=True)
7633 7634
7635 - def test_show_apod_extract(self):
7636 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7637 7638 # The path to the data files. 7639 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7640 7641 # Define file name. 7642 file_name = '128_0_FT.ft2' 7643 7644 # Call function. 7645 get_output = show_apod_extract(file_name=file_name, dir=data_path) 7646 7647 # Define how output should look like. 7648 # The output from showApod differs slightly according to NMRPipe version. But 'Noise Std Dev' is the same. 7649 # Dont test lines which can differ. 7650 show_apod_ver = [ 7651 'REMARK Effect of Processing on Peak Parameters and Noise for %s'%(data_path+sep+file_name), 7652 'REMARK Automated Noise Std Dev in Processed Data: 8583.41', 7653 'REMARK Noise Std Dev Before Processing H1 and N15: 60.6558', 7654 '', 7655 'VARS AXIS LABEL TSIZE FSIZE LW_ADJ LW_FINAL HI_FACTOR VOL_FACTOR SIGMA_FACTOR', 7656 'FORMAT %s %-8s %4d %4d %7.4f %7.4f %.4e %.4e %.4e'] 7657 #'', 7658 #' X H1 800 2048 0.8107 3.7310 4.9903e-03 9.8043e-04 5.2684e-02', 7659 #' Y N15 128 256 0.7303 3.0331 3.1260e-02 7.8434e-03 1.3413e-01'] 7660 7661 for i, line in enumerate(show_apod_ver): 7662 line_ver = get_output[i] 7663 7664 print(line) 7665 if line[:50] == 'REMARK Noise Std Dev Before Processing H1 and N15:': 7666 continue 7667 # Make the string test 7668 self.assertEqual(line, line_ver)
7669 7670
7671 - def test_show_apod_rmsd(self):
7672 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod.""" 7673 7674 # The path to the data files. 7675 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7676 7677 # Define file name. 7678 file_name = '128_0_FT.ft2' 7679 7680 # Call function. 7681 rmsd = show_apod_rmsd(file_name=file_name, dir=data_path) 7682 7683 # Assert. 7684 self.assertEqual(rmsd, 8583.41)
7685 7686
7688 """Test searching for all NMRPipe spectrum files in dir, call showApod, and write to files.""" 7689 7690 # The path to the data files. 7691 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7692 7693 # Call function, and get all file names. 7694 wfile_paths = show_apod_rmsd_dir_to_files(file_ext='.ft2', dir=data_path, outdir=self.tmpdir) 7695 7696 # Loop over file_paths. 7697 for wfile_path in wfile_paths: 7698 # Open the file. 7699 get_data = extract_data(file=wfile_path) 7700 7701 # Extract line 0, column 0. 7702 test = float(get_data[0][0]) 7703 7704 # Assert. 7705 self.assertEqual(test, 8583.41)
7706 7707
7709 """Test getting the spectrum noise for spectrum fourier transformed with NMRPipe, and tool showApod, and write to file.""" 7710 7711 # The path to the data files. 7712 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'repeated_analysis'+sep+'SOD1'+sep+'cpmg_disp_sod1d90a_060518'+sep+'cpmg_disp_sod1d90a_060518_normal.fid'+sep+'ft2_data' 7713 7714 # Define file name. 7715 file_name = '128_0_FT.ft2' 7716 7717 # Call function, and get file name. 7718 wfile_path = show_apod_rmsd_to_file(file_name=file_name, dir=data_path, outdir=self.tmpdir) 7719 7720 # Open the file. 7721 get_data = extract_data(file=wfile_path) 7722 7723 # Extract line 0, column 0. 7724 test = float(get_data[0][0]) 7725 7726 # Assert. 7727 self.assertEqual(test, 8583.41)
7728 7729
7731 """Error analysis of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7732 7733 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7734 'SOD1-WT' CPMG data to the CR72 dispersion model. 7735 7736 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7737 Data is for experiment at 25 degree Celcius. 7738 7739 bug #21954 U{https://gna.org/bugs/index.php?21954}: Order of spectrum.error_analysis is important. 7740 """ 7741 7742 # Base data setup. 7743 pipe_name = 'base pipe' 7744 pipe_type = 'relax_disp' 7745 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7746 select_spin_index = list(range(0, 1)) 7747 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7748 7749 # Define replicated 7750 repl_A = ['Z_A1', 'Z_A15'] 7751 repl_B = ['Z_B1', 'Z_B18'] 7752 7753 # Loop over spectrum ID, and sort them 7754 spectrum_ids_A = [] 7755 spectrum_ids_B = [] 7756 for spectrum_id in cdp.spectrum_ids: 7757 if "A" in spectrum_id: 7758 spectrum_ids_A.append(spectrum_id) 7759 elif "B" in spectrum_id: 7760 spectrum_ids_B.append(spectrum_id) 7761 7762 # To clean up old error analysis, delete attributes 7763 delattr(cdp, "var_I") 7764 delattr(cdp, "sigma_I") 7765 7766 # Perform error analysis 7767 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7768 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7769 7770 # Loop over spins, save errors to list 7771 Errors_A_B = [] 7772 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7773 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7774 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7775 Errors_A_B.append([A_err, B_err]) 7776 7777 # To clean up old error analysis, delete attributes 7778 delattr(cdp, "var_I") 7779 delattr(cdp, "sigma_I") 7780 7781 # Perform error analysis. Order is important 7782 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_B) 7783 self.interpreter.spectrum.error_analysis(subset=spectrum_ids_A) 7784 7785 # Loop over spins, save errors to list 7786 Errors_B_A = [] 7787 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7788 A_err = spin.peak_intensity_err[spectrum_ids_A[0]] 7789 B_err = spin.peak_intensity_err[spectrum_ids_B[0]] 7790 Errors_B_A.append([A_err, B_err]) 7791 7792 # Make test for order of error 7793 for i in range(len(Errors_A_B)): 7794 Error_A_B = Errors_A_B[i] 7795 Error_B_A = Errors_B_A[i] 7796 self.assertAlmostEqual(Error_A_B[0], Error_B_A[0], 4) 7797 self.assertAlmostEqual(Error_A_B[1], Error_B_A[1], 4) 7798 7799 # Make further tests for fixed values 7800 std_A = math.sqrt((cdp.var_I[repl_A[0]] + cdp.var_I[repl_A[1]])/2) 7801 std_A_fix = 2785.7263335738567 7802 7803 for id_A in spectrum_ids_A: 7804 self.assertEqual(cdp.sigma_I[id_A], std_A) 7805 self.assertAlmostEqual(cdp.sigma_I[id_A], std_A_fix, 7) 7806 7807 std_B = math.sqrt((cdp.var_I[repl_B[0]] + cdp.var_I[repl_B[1]])/2) 7808 std_B_fix = 4967.3772030667988 7809 7810 for id_B in spectrum_ids_B: 7811 self.assertEqual(cdp.sigma_I[id_B], std_B) 7812 self.assertAlmostEqual(cdp.sigma_I[id_B], std_B_fix, 7)
7813 7814
7815 - def test_sod1wt_t25_to_cr72(self):
7816 """Optimisation of SOD1-WT CPMG. From paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. 7817 7818 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7819 'SOD1-WT' CPMG data to the CR72 dispersion model. 7820 7821 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7822 Data is for experiment at 25 degree Celcius. 7823 """ 7824 7825 # Base data setup. 7826 pipe_name = 'base pipe' 7827 pipe_type = 'relax_disp' 7828 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7829 select_spin_index = list(range(0, 2)) 7830 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7831 7832 # Generate r20 key. 7833 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 7834 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 7835 7836 ## Now prepare for MODEL calculation. 7837 MODEL = "CR72" 7838 7839 # Change pipe. 7840 pipe_name_MODEL = "%s_%s"%(pipe_name, MODEL) 7841 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL) 7842 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL) 7843 7844 # Then select model. 7845 self.interpreter.relax_disp.select_model(model=MODEL) 7846 7847 # GRID inc of 7 was found to be appropriate not to find pA = 0.5. 7848 GRID_INC = 7 7849 7850 # Store grid and minimisations results. 7851 grid_results = [] 7852 mini_results = [] 7853 clust_results = [] 7854 7855 # Set the R20 parameters in the default grid search using the minimum R2eff value. 7856 self.interpreter.relax_disp.r20_from_min_r2eff(force=False) 7857 7858 # Deselect insignificant spins. 7859 self.interpreter.relax_disp.insignificance(level=1.0) 7860 7861 # Perform Grid Search. 7862 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=GRID_INC, constraints=True, verbosity=1) 7863 7864 # Store result. 7865 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7866 # Store grid results. 7867 grid_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7868 7869 ## Now do minimisation. 7870 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 7871 set_func_tol = 1e-9 7872 set_max_iter = 100000 7873 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7874 7875 # Store result. 7876 pA_values = [] 7877 kex_values = [] 7878 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7879 # Store minimisation results. 7880 mini_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7881 7882 # Store pA values. 7883 pA_values.append(spin.pA) 7884 7885 # Store kex values. 7886 kex_values.append(spin.kex) 7887 7888 print("\n# Now print before and after minimisation.\n") 7889 7890 # Print results. 7891 for i in range(len(grid_results)): 7892 # Get values. 7893 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7894 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7895 7896 print("GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7897 print("MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7898 7899 ## Prepare for clustering 7900 # Change pipe. 7901 pipe_name_MODEL_CLUSTER = "%s_%s_Cluster"%(pipe_name, MODEL) 7902 self.interpreter.pipe.copy(pipe_from=pipe_name_r2eff, pipe_to=pipe_name_MODEL_CLUSTER) 7903 self.interpreter.pipe.switch(pipe_name=pipe_name_MODEL_CLUSTER) 7904 7905 # Then select model. 7906 self.interpreter.relax_disp.select_model(model=MODEL) 7907 7908 # Define cluster id. 7909 cluster_id = 'clust' 7910 7911 # Loop over spins to cluster them. 7912 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7913 self.interpreter.relax_disp.cluster(cluster_id, spin_id) 7914 7915 # Copy over values. 7916 self.interpreter.relax_disp.parameter_copy(pipe_from=pipe_name_MODEL, pipe_to=pipe_name_MODEL_CLUSTER) 7917 7918 # Test the median values is correct 7919 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7920 print(pA_values) 7921 # The the median pA value returned. 7922 self.assertEqual(median(pA_values), spin.pA) 7923 7924 # The the median kex value returned. 7925 self.assertEqual(median(kex_values), spin.kex) 7926 7927 ## Now do minimisation. 7928 self.interpreter.minimise.execute(min_algor='simplex', func_tol=set_func_tol, max_iter=set_max_iter, constraints=True, scaling=True, verbosity=1) 7929 7930 # Store result. 7931 for spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 7932 # Store clust results. 7933 clust_results.append([spin.r2[r20_key_600], spin.r2[r20_key_500], spin.dw, spin.pA, spin.kex, spin.chi2, spin_id, resi, resn]) 7934 7935 # Store the outcome of the clustering minimisation. 7936 clust_pA = spin.pA 7937 clust_kex = spin.kex 7938 7939 print("\n# Now testing.\n") 7940 7941 # Define results 7942 test_res = {} 7943 test_res[':10@N'] = {} 7944 test_res[':10@N']['r2600'] = 18.429755324773360 7945 test_res[':10@N']['r2500'] = 16.981349161968630 7946 test_res[':10@N']['dw'] = 2.700755859433969 7947 test_res[':10@N']['pA'] = 0.971531659288657 7948 test_res[':10@N']['kex'] = 3831.766337047963134 7949 test_res[':11@N'] = {} 7950 test_res[':11@N']['r2600'] = 18.193409421115213 7951 test_res[':11@N']['r2500'] = 17.308838135567765 7952 test_res[':11@N']['dw'] = 2.706650302761793 7953 test_res[':11@N']['pA'] = 0.971531659288657 7954 test_res[':11@N']['kex'] = 3831.766337047963134 7955 7956 # Then make tests. 7957 for i in range(len(grid_results)): 7958 # Get values. 7959 g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn = grid_results[i] 7960 m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn = mini_results[i] 7961 c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn = clust_results[i] 7962 7963 print("%s GRID r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(g_spin_id, g_r2_600, g_r2_500, g_dw, g_pA, g_kex, g_chi2, g_spin_id, g_resi, g_resn)) 7964 print("%s MIN r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, m_r2_600, m_r2_500, m_dw, m_pA, m_kex, m_chi2, m_spin_id, m_resi, m_resn)) 7965 print("%s Clust r2600=%2.2f r2500=%2.2f dw=%1.1f pA=%1.3f kex=%3.2f chi2=%3.2f spin_id=%s resi=%i resn=%s"%(m_spin_id, c_r2_600, c_r2_500, c_dw, c_pA, c_kex, c_chi2, c_spin_id, c_resi, c_resn)) 7966 7967 # Make tests. 7968 self.assertEqual(clust_pA, c_pA) 7969 self.assertEqual(clust_kex, c_kex) 7970 7971 # Test values. 7972 if c_spin_id in test_res: 7973 self.assertAlmostEqual(c_r2_600, test_res[c_spin_id]['r2600'], 4) 7974 self.assertAlmostEqual(c_r2_500, test_res[c_spin_id]['r2500'], 4) 7975 self.assertAlmostEqual(c_dw, test_res[c_spin_id]['dw'], 3) 7976 self.assertAlmostEqual(c_pA, test_res[c_spin_id]['pA'], 5) 7977 self.assertAlmostEqual(c_kex, test_res[c_spin_id]['kex'], 1)
7978 7979 # Save disp graph to temp. 7980 #self.interpreter.relax_disp.plot_disp_curves(dir="~"+sep+"test", num_points=1000, extend=500.0, force=True). 7981 7982
7984 """Conversion of SOD1-WT CPMG R2eff values into input files for sherekhan. 7985 7986 Optimisation of Kaare Teilum, Melanie H. Smith, Eike Schulz, Lea C. Christensen, Gleb Solomentseva, Mikael Oliveberg, and Mikael Akkea 2009 7987 'SOD1-WT' CPMG data to the CR72 dispersion model. 7988 7989 This uses the data from paper at U{http://dx.doi.org/10.1073/pnas.0907387106}. This is CPMG data with a fixed relaxation time period recorded at fields of 500 and 600MHz. 7990 Data is for experiment at 25 degree Celcius. 7991 """ 7992 7993 # Base data setup. 7994 pipe_name = 'base pipe' 7995 pipe_type = 'relax_disp' 7996 pipe_name_r2eff = "%s_R2eff"%(pipe_name) 7997 select_spin_index = list(range(0, 2)) 7998 self.setup_sod1wt_t25(pipe_name=pipe_name, pipe_type=pipe_type, pipe_name_r2eff=pipe_name_r2eff, select_spin_index=select_spin_index) 7999 8000 # Generate r20 key. 8001 r20_key_600 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=599.8908617*1E6) 8002 r20_key_500 = generate_r20_key(exp_type=EXP_TYPE_CPMG_SQ, frq=499.862139*1E6) 8003 8004 # Cluster everything, to analyse together. 8005 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":1-1000") 8006 8007 # Write input 8008 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=ds.tmpdir) 8009 8010 # Check the r2eff set files. 8011 print("\nChecking the R2eff input set files.") 8012 files = [[ds.tmpdir + sep + 'cluster1', 'sherekhan_frq1.in'], [ ds.tmpdir + sep + 'cluster1', 'sherekhan_frq2.in']] 8013 8014 # First check file exists 8015 for dir, file in files: 8016 print(dir+sep+file) 8017 self.assert_(access(dir+sep+file, F_OK)) 8018 8019 # Define how files should look like 8020 data_set_600 = [ 8021 "60.8272464287\n", 8022 "0.06\n", 8023 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8024 "# G10\n", 8025 " 33.333 26.53556078711 0.5236104771163\n", 8026 " 66.667 25.29735243318 0.48766574122\n", 8027 " 100 25.09470361403 0.4820438864671\n", 8028 " 133.333 25.15603274331 0.4837377286085\n", 8029 " 166.667 24.27213341753 0.4599457904395\n", 8030 " 200 24.00364120328 0.4529773198905\n", 8031 " 266.667 24.03511395168 0.4537880662536\n", 8032 " 300 23.04761040024 0.4291039120557\n", 8033 " 333.333 22.95530300787 0.4268745963972\n", 8034 " 400 23.06158810662 0.4294426293624\n", 8035 " 466.667 22.26799054092 0.4106809618644\n", 8036 " 533.333 21.99851418823 0.4045232104735\n", 8037 " 666.667 21.19651570955 0.3868136173831\n", 8038 " 833.333 20.30938498379 0.3682604887899\n", 8039 " 1000 20.28273252609 0.367719392568\n", 8040 "# D11\n", 8041 " 33.333 24.76520269878 0.5026475808706\n", 8042 " 66.667 24.8773107448 0.5058752916906\n", 8043 " 100 24.90357815239 0.5066348551479\n", 8044 " 133.333 23.7782506151 0.4751950583865\n", 8045 " 166.667 23.68548762076 0.4727017128631\n", 8046 " 200 23.58629651618 0.4700517377679\n", 8047 " 266.667 23.47734671187 0.4671601744044\n", 8048 " 300 24.08647493772 0.4835855560598\n", 8049 " 333.333 22.98314371029 0.4542918950801\n", 8050 " 400 22.80339361568 0.4497107885587\n", 8051 " 466.667 22.91634335366 0.4525833037874\n", 8052 " 533.333 22.59774140046 0.4445334311324\n", 8053 " 666.667 20.9177750759 0.4046955726046\n", 8054 " 833.333 20.71792550566 0.4002363835007\n", 8055 " 1000 19.54080006349 0.3751112751853\n", 8056 ] 8057 8058 # Check data_set_600 8059 file = open(files[0][0]+sep+files[0][1]) 8060 lines = file.readlines() 8061 file.close() 8062 self.assertEqual(len(data_set_600), len(lines)) 8063 for i in range(len(data_set_600)): 8064 # Make the string test 8065 self.assertEqual(data_set_600[i], lines[i]) 8066 8067 # Define how files should look like 8068 data_set_500 = [ 8069 "50.6846152368\n", 8070 "0.04\n", 8071 "# nu_cpmg (Hz) R2eff (rad/s) Error \n", 8072 "# G10\n", 8073 " 50 22.28084307393 0.2944966344183\n", 8074 " 100 21.93494977761 0.2910362768307\n", 8075 " 150 21.09850032232 0.282892238351\n", 8076 " 200 20.86493960397 0.2806737853646\n", 8077 " 250 20.75287269752 0.2796178205016\n", 8078 " 300 20.25597152406 0.2750013546989\n", 8079 " 350 19.92172163467 0.2719555756504\n", 8080 " 400 19.97712052922 0.272457105051\n", 8081 " 450 19.46807010415 0.2678972122793\n", 8082 " 500 19.76875460947 0.2705774849203\n", 8083 " 550 19.39161367402 0.2672216964327\n", 8084 " 600 19.03949517697 0.2641417899694\n", 8085 " 650 19.12218812132 0.2648605059901\n", 8086 " 700 19.01037461457 0.2638893584683\n", 8087 " 800 18.83395162904 0.2623674321143\n", 8088 " 900 18.47529972436 0.2593123604687\n", 8089 " 1000 18.5252023121 0.2597343394038\n", 8090 "# D11\n", 8091 " 50 22.15403890237 0.3285588379827\n", 8092 " 100 21.80946781746 0.3247185598713\n", 8093 " 150 21.77715415505 0.324361526682\n", 8094 " 200 21.41647464235 0.3204122024881\n", 8095 " 250 21.17099940822 0.3177616325958\n", 8096 " 300 21.03740030577 0.3163316496664\n", 8097 " 350 20.95393648281 0.3154427665172\n", 8098 " 400 20.93311399332 0.315221543436\n", 8099 " 450 20.18219905222 0.3073848655291\n", 8100 " 500 19.93599065085 0.3048744697057\n", 8101 " 550 19.68475725452 0.3023424499113\n", 8102 " 600 19.33575433934 0.2988741928798\n", 8103 " 650 19.53915692194 0.3008886196853\n", 8104 " 700 19.2018754351 0.2975587767134\n", 8105 " 800 18.82360965368 0.2938866923878\n", 8106 " 900 18.71861761238 0.2928790380131\n", 8107 " 1000 17.95878049287 0.2857341721151\n", 8108 ] 8109 8110 # Check data_set_500 8111 file = open(files[1][0]+sep+files[1][1]) 8112 lines = file.readlines() 8113 file.close() 8114 self.assertEqual(len(data_set_500), len(lines)) 8115 for i in range(len(data_set_500)): 8116 # Make the string test 8117 self.assertEqual(data_set_500[i], lines[i]) 8118 8119 # Test local dir tests. This will be turned off in system test. 8120 turn_on_local_dir_test = False 8121 8122 if turn_on_local_dir_test: 8123 ## Now check to local folder with None argument. 8124 # Write input 8125 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None) 8126 8127 # Check the r2eff set files. 8128 print("\nChecking the R2eff input set files.") 8129 files = [[path.join(getcwd(), 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), 'cluster1'), 'sherekhan_frq2.in']] 8130 8131 # First check file exists 8132 for dir, file in files: 8133 print(dir+sep+file) 8134 self.assert_(access(dir+sep+file, F_OK)) 8135 8136 ## Now check to local folder with dir argument. 8137 # Write input 8138 set_dir = "Test_ShereKhan" 8139 self.interpreter.relax_disp.sherekhan_input(force=True, spin_id=None, dir=set_dir) 8140 8141 # Check the r2eff set files. 8142 print("\nChecking the R2eff input set files.") 8143 files = [[path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq1.in'], [path.join(getcwd(), set_dir, 'cluster1'), 'sherekhan_frq2.in']] 8144 8145 # First check file exists 8146 for dir, file in files: 8147 print(dir+sep+file) 8148 self.assert_(access(dir+sep+file, F_OK))
8149 8150
8151 - def test_sprangers_data_to_mmq_cr72(self, model=None):
8152 """Test the 'MMQ CR72' model fitting against Remco Sprangers' ClpP data. 8153 8154 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MMQ CPMG data with a fixed relaxation time period. 8155 """ 8156 8157 # Reset. 8158 self.interpreter.reset() 8159 8160 # Create the data pipe and load the base data. 8161 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8162 self.interpreter.state.load(data_path+sep+'r2eff_values') 8163 8164 # The model data pipe. 8165 model = 'MMQ CR72' 8166 pipe_name = "%s - relax_disp" % model 8167 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8168 self.interpreter.pipe.switch(pipe_name=pipe_name) 8169 8170 # Set the model. 8171 self.interpreter.relax_disp.select_model(model=model) 8172 8173 # Cluster everything. 8174 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8175 8176 # Copy the data. 8177 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8178 8179 # Alias the spins. 8180 spin135S = cdp.mol[0].res[0].spin[0] 8181 spin135F = cdp.mol[0].res[0].spin[1] 8182 spin137S = cdp.mol[0].res[1].spin[0] 8183 spin137F = cdp.mol[0].res[1].spin[1] 8184 8185 # The R20 keys. 8186 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=600e6) 8187 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8188 8189 # Set the cluster specific parameters (only for the first spin). 8190 spin135S.pA = 0.836591763632 8191 spin135S.kex = 241.806525261 8192 8193 # Set the initial parameter values. 8194 spin135S.r2 = {r20_key1: 28.2493431552, r20_key2: 31.7517334715} 8195 spin135S.dw = 0.583003118785 8196 spin135S.dwH = 0.0361441944301 8197 8198 spin135F.r2 = {r20_key1: 42.7201839991, r20_key2: 57.3178617389} 8199 spin135F.dw = 0.805849745104 8200 spin135F.dwH = 0.0215791945715 8201 8202 spin137S.r2 = {r20_key1: 26.0134115256, r20_key2: 30.575806934} 8203 spin137S.dw = 0.688107568372 8204 spin137S.dwH = 0.0344463604043 8205 8206 spin137F.r2 = {r20_key1: 46.6969397337, r20_key2: 58.602384101} 8207 spin137F.dw = 0.94978299907 8208 spin137F.dwH = 1.4818877939e-07 8209 8210 # Low precision optimisation. 8211 self.interpreter.minimise.execute(min_algor='simplex', func_tol=1e-10, max_iter=1000) 8212 8213 # Printout. 8214 print("\n\nOptimised parameters:\n") 8215 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8216 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8217 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8218 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8219 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8220 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8221 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8222 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8223 print("\n # Set the cluster specific parameters (only for the first spin).") 8224 print(" spin135S.pA = %s" % spin135S.pA) 8225 print(" spin135S.kex = %s" % spin135S.kex) 8226 print("\n # Set the initial parameter values.") 8227 print(" spin135S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135S.r2[r20_key1], spin135S.r2[r20_key2])) 8228 print(" spin135S.dw = %s" % spin135S.dw) 8229 print(" spin135S.dwH = %s" % spin135S.dwH) 8230 print("\n spin135F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin135F.r2[r20_key1], spin135F.r2[r20_key2])) 8231 print(" spin135F.dw = %s" % spin135F.dw) 8232 print(" spin135F.dwH = %s" % spin135F.dwH) 8233 print("\n spin137S.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137S.r2[r20_key1], spin137S.r2[r20_key2])) 8234 print(" spin137S.dw = %s" % spin137S.dw) 8235 print(" spin137S.dwH = %s" % spin137S.dwH) 8236 print("\n spin137F.r2 = {r20_key1: %s, r20_key2: %s}" % (spin137F.r2[r20_key1], spin137F.r2[r20_key2])) 8237 print(" spin137F.dw = %s" % spin137F.dw) 8238 print(" spin137F.dwH = %s" % spin137F.dwH) 8239 8240 # Checks for residue :135S. 8241 self.assertAlmostEqual(spin135S.r2[r20_key1], 28.2493445347425, 4) 8242 self.assertAlmostEqual(spin135S.r2[r20_key2], 31.7517352342937, 4) 8243 self.assertAlmostEqual(spin135S.pA, 0.836591714049569, 4) 8244 self.assertAlmostEqual(spin135S.dw, 0.583003004605869, 4) 8245 self.assertAlmostEqual(spin135S.dwH, 0.0361441894065963, 4) 8246 self.assertAlmostEqual(spin135S.kex/100, 241.806464344233/100, 4) 8247 self.assertAlmostEqual(spin135S.chi2, 12.4224060116473, 4) 8248 8249 # Checks for residue :135F. 8250 self.assertAlmostEqual(spin135F.r2[r20_key1], 42.7201844426839, 4) 8251 self.assertAlmostEqual(spin135F.r2[r20_key2], 57.3178718548898, 4) 8252 self.assertAlmostEqual(spin135F.pA, 0.836591714049569, 4) 8253 self.assertAlmostEqual(spin135F.dw, 0.805849748711916, 4) 8254 self.assertAlmostEqual(spin135F.dwH, 0.0215791669142752, 4) 8255 self.assertAlmostEqual(spin135F.kex/100, 241.806464344233/100, 4) 8256 self.assertAlmostEqual(spin135F.chi2, 12.4224060116473, 4) 8257 8258 # Checks for residue :137S. 8259 self.assertAlmostEqual(spin137S.r2[r20_key1], 26.013412509919, 4) 8260 self.assertAlmostEqual(spin137S.r2[r20_key2], 30.5758092335097, 4) 8261 self.assertAlmostEqual(spin137S.pA, 0.836591714049569, 4) 8262 self.assertAlmostEqual(spin137S.dw, 0.688107406812537, 4) 8263 self.assertAlmostEqual(spin137S.dwH, 0.034446357344577, 4) 8264 self.assertAlmostEqual(spin137S.kex/100, 241.806464344233/100, 4) 8265 self.assertAlmostEqual(spin137S.chi2, 12.4224060116473, 4) 8266 8267 # Checks for residue :137F. 8268 self.assertAlmostEqual(spin137F.r2[r20_key1], 46.696935090697, 4) 8269 self.assertAlmostEqual(spin137F.r2[r20_key2], 58.6023842513446, 4) 8270 self.assertAlmostEqual(spin137F.pA, 0.836591714049569, 4) 8271 self.assertAlmostEqual(spin137F.dw, 0.94978325541294, 4) 8272 self.assertAlmostEqual(spin137F.dwH, 1.5189362257653e-07, 4) 8273 self.assertAlmostEqual(spin137F.kex/100, 241.806464344233/100, 4) 8274 self.assertAlmostEqual(spin137F.chi2, 12.4224060116473, 4)
8275 8276
8277 - def test_sprangers_data_to_ns_mmq_2site(self, model=None):
8278 """Test the 'NS MMQ 2-site' model fitting against Remco Sprangers' ClpP data. 8279 8280 This uses the data from Remco Sprangers' paper at http://dx.doi.org/10.1073/pnas.0507370102. This is MQ CPMG data with a fixed relaxation time period. 8281 """ 8282 8283 # Reset. 8284 self.interpreter.reset() 8285 8286 # Create the data pipe and load the base data. 8287 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Sprangers_ClpP' 8288 self.interpreter.state.load(data_path+sep+'r2eff_values') 8289 8290 # The model data pipe. 8291 model = 'NS MMQ 2-site' 8292 pipe_name = "%s - relax_disp" % model 8293 self.interpreter.pipe.copy(pipe_from='base pipe', pipe_to=pipe_name, bundle_to='relax_disp') 8294 self.interpreter.pipe.switch(pipe_name=pipe_name) 8295 8296 # Set the model. 8297 self.interpreter.relax_disp.select_model(model=model) 8298 8299 # Cluster everything. 8300 self.interpreter.relax_disp.cluster(cluster_id='all', spin_id=":135-137") 8301 8302 # Copy the data. 8303 self.interpreter.value.copy(pipe_from='R2eff', pipe_to=pipe_name, param='r2eff') 8304 8305 # Alias the spins. 8306 spin135S = cdp.mol[0].res[0].spin[0] 8307 spin135F = cdp.mol[0].res[0].spin[1] 8308 spin137S = cdp.mol[0].res[1].spin[0] 8309 spin137F = cdp.mol[0].res[1].spin[1] 8310 8311 # The R20 keys. 8312 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8313 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_CPMG_MQ, frq=800e6) 8314 8315 # Set the cluster specific parameters (only for the first spin). 8316 spin135S.pA = 0.847378444499757 8317 spin135S.kex = 264.055604934724329 8318 8319 # Set the initial parameter values. 8320 spin135S.r2 = {r20_key1: 30.315119723745390, r20_key2: 37.411874745645299} 8321 spin135S.dw = 0.585574008745351 8322 spin135S.dwH = 0.000000000000002 8323 8324 spin135F.r2 = {r20_key1: 41.440843383778287, r20_key2: 56.989726795397893} 8325 spin135F.dw = 0.856699277665748 8326 spin135F.dwH = 0.000000000582587 8327 8328 spin137S.r2 = {r20_key1: 23.051695938570266, r20_key2: 28.352806483953824} 8329 spin137S.dw = 0.772904450844973 8330 spin137S.dwH = 0.183351478512970 8331 8332 spin137F.r2 = {r20_key1: 44.702032074210429, r20_key2: 56.453146052685319} 8333 spin137F.dw = 0.984568590342831 8334 spin137F.dwH = 0.000000001993458 8335 8336 # Low precision optimisation. 8337 self.interpreter.minimise.execute(min_algor='simplex', line_search=None, hessian_mod=None, hessian_type=None, func_tol=1e-5, grad_tol=None, max_iter=100, constraints=True, scaling=True, verbosity=1) 8338 8339 # Printout. 8340 print("\n\nOptimised parameters:\n") 8341 print("%-20s %-20s %-20s %-20s %-20s" % ("Parameter", "Value (:135@S)", "Value (:135@F)", "Value (:137@S)", "Value (:137@F)")) 8342 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (500 MHz)", spin135S.r2[r20_key1], spin135F.r2[r20_key1], spin137S.r2[r20_key1], spin137F.r2[r20_key1])) 8343 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("R2 (800 MHz)", spin135S.r2[r20_key2], spin135F.r2[r20_key2], spin137S.r2[r20_key2], spin137F.r2[r20_key2])) 8344 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("pA", spin135S.pA, spin135F.pA, spin137S.pA, spin137F.pA)) 8345 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dw", spin135S.dw, spin135F.dw, spin137S.dw, spin137F.dw)) 8346 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("dwH", spin135S.dwH, spin135F.dwH, spin137S.dwH, spin137F.dwH)) 8347 print("%-20s %20.15g %20.15g %20.15g %20.15g" % ("kex", spin135S.kex, spin135F.kex, spin137S.kex, spin137F.kex)) 8348 print("%-20s %20.15g %20.15g %20.15g %20.15g\n" % ("chi2", spin135S.chi2, spin135F.chi2, spin137S.chi2, spin137F.chi2)) 8349 8350 # FIXME: Remove this temporary return and properly check the results. 8351 return 8352 8353 # Checks for residue :135S. 8354 self.assertAlmostEqual(spin135S.r2[r20_key1], 30.3151197237454, 4) 8355 self.assertAlmostEqual(spin135S.r2[r20_key2], 37.4118747456453, 4) 8356 self.assertAlmostEqual(spin135S.pA, 0.847378444499757, 4) 8357 self.assertAlmostEqual(spin135S.dw, 0.585574008745351, 4) 8358 self.assertAlmostEqual(spin135S.dwH, 2e-15, 4) 8359 self.assertAlmostEqual(spin135S.kex, 264.055604934724, 4) 8360 self.assertAlmostEqual(spin135S.chi2, 13.859423588071, 1) 8361 8362 # Checks for residue :135F. 8363 self.assertAlmostEqual(spin135F.r2[r20_key1], 41.4408433837783, 4) 8364 self.assertAlmostEqual(spin135F.r2[r20_key2], 56.9897267953979, 4) 8365 self.assertAlmostEqual(spin135F.pA, 0.847378444499757, 4) 8366 self.assertAlmostEqual(spin135F.dw, 0.856699277665748, 4) 8367 self.assertAlmostEqual(spin135F.dwH, 5.82587e-10, 4) 8368 self.assertAlmostEqual(spin135F.kex, 264.055604934724, 4) 8369 self.assertAlmostEqual(spin135F.chi2, 13.859423588071, 1) 8370 8371 # Checks for residue :137S. 8372 self.assertAlmostEqual(spin137S.r2[r20_key1], 23.0516959385703, 4) 8373 self.assertAlmostEqual(spin137S.r2[r20_key2], 28.3528064839538, 4) 8374 self.assertAlmostEqual(spin137S.pA, 0.847378444499757, 4) 8375 self.assertAlmostEqual(spin137S.dw, 0.772904450844973, 4) 8376 self.assertAlmostEqual(spin137S.dwH, 0.18335147851297, 4) 8377 self.assertAlmostEqual(spin137S.kex, 264.055604934724, 4) 8378 self.assertAlmostEqual(spin137S.chi2, 13.859423588071, 1) 8379 8380 # Checks for residue :137F. 8381 self.assertAlmostEqual(spin137F.r2[r20_key1], 44.7020320742104, 4) 8382 self.assertAlmostEqual(spin137F.r2[r20_key2], 56.4531460526853, 4) 8383 self.assertAlmostEqual(spin137F.pA, 0.847378444499757, 4) 8384 self.assertAlmostEqual(spin137F.dw, 0.984568590342831, 4) 8385 self.assertAlmostEqual(spin137F.dwH, 2.0931309e-09, 4) 8386 self.assertAlmostEqual(spin137F.kex, 264.055604934724, 4) 8387 self.assertAlmostEqual(spin137F.chi2, 13.859423588071, 1)
8388 8389
8390 - def test_tp02_data_to_ns_r1rho_2site(self, model=None):
8391 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data.""" 8392 8393 # Setup the data. 8394 self.setup_tp02_data_to_ns_r1rho_2site() 8395 8396 # Alias the spins. 8397 spin1 = cdp.mol[0].res[0].spin[0] 8398 spin2 = cdp.mol[0].res[1].spin[0] 8399 8400 # The R20 keys. 8401 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8402 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8403 8404 # Checks for residue :1. 8405 self.assertAlmostEqual(spin1.r2[r20_key1], 8.50207717367548, 4) 8406 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4680429589972, 4) 8407 self.assertAlmostEqual(spin1.pA, 0.864523128842393, 4) 8408 self.assertAlmostEqual(spin1.dw, 8.85204828994151, 4) 8409 self.assertAlmostEqual(spin1.kex/1000, 1199.56359549637/1000, 4) 8410 self.assertAlmostEqual(spin1.chi2, 2.99182130153514, 4) 8411 8412 # Checks for residue :2. 8413 self.assertAlmostEqual(spin2.r2[r20_key1], 10.2099357790203, 4) 8414 self.assertAlmostEqual(spin2.r2[r20_key2], 16.2137648697873, 4) 8415 self.assertAlmostEqual(spin2.pA, 0.836488681031685, 4) 8416 self.assertAlmostEqual(spin2.dw, 9.5505714779503, 4) 8417 self.assertAlmostEqual(spin2.kex/1000, 1454.45726998929/1000, 4) 8418 self.assertAlmostEqual(spin2.chi2, 0.000402231563481261, 4)
8419 8420
8421 - def test_tp02_data_to_ns_r1rho_2site_cluster(self, model=None):
8422 """Test the relaxation dispersion 'NS R1rho 2-site' model fitting against the 'TP02' test data, when performing clustering.""" 8423 8424 # Setup the data. 8425 self.setup_tp02_data_to_ns_r1rho_2site(clustering=True) 8426 8427 # Alias the spins. 8428 spin1 = cdp.mol[0].res[0].spin[0] 8429 spin2 = cdp.mol[0].res[1].spin[0] 8430 8431 # The R20 keys. 8432 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8433 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8434 8435 # Checks for residue :1. 8436 self.assertAlmostEqual(spin1.r2[r20_key1], 8.48607207881462, 4) 8437 self.assertAlmostEqual(spin1.r2[r20_key2], 13.4527609061722, 4) 8438 self.assertAlmostEqual(spin1.pA, 0.863093838784425, 4) 8439 self.assertAlmostEqual(spin1.dw, 8.86218096536618, 4) 8440 self.assertAlmostEqual(spin1.kex/1000, 1186.22749648299/1000, 4) 8441 self.assertAlmostEqual(spin1.chi2, 3.09500996065247, 4) 8442 8443 # Checks for residue :2. 8444 self.assertAlmostEqual(spin2.r2[r20_key1], 10.4577906018883, 4) 8445 self.assertAlmostEqual(spin2.r2[r20_key2], 16.4455550953792, 4) 8446 self.assertAlmostEqual(spin2.pA, 0.863093838784425, 4) 8447 self.assertAlmostEqual(spin2.dw, 11.5841168862587, 4) 8448 self.assertAlmostEqual(spin2.kex/1000, 1186.22749648299/1000, 4) 8449 self.assertAlmostEqual(spin2.chi2, 3.09500996065247, 4)
8450 8451
8452 - def test_tp02_data_to_mp05(self):
8453 """Test the dispersion 'MP05' model fitting against the 'TP02' test data.""" 8454 8455 # Fixed time variable and the models. 8456 ds.fixed = True 8457 ds.models = ['R2eff', 'MP05'] 8458 8459 # Execute the script. 8460 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8461 8462 # Switch back to the data pipe for the optimisation. 8463 self.interpreter.pipe.switch('MP05 - relax_disp') 8464 8465 # The equivalent MP05 parameters. 8466 r1rho_prime = [[10.0058086343329, 15.005806870124], [12.0766320470785, 18.0767503536277]] 8467 pA = [0.775055484521586, 0.500000000036595] 8468 kex = [1235.20361276079, 2378.31403454691] 8469 delta_omega = [7.08194146569694, 5.4083562844306] 8470 chi2 = [0.0370400968727768, 0.182141732163934] 8471 8472 # Alias the spins. 8473 spin1 = cdp.mol[0].res[0].spin[0] 8474 spin2 = cdp.mol[0].res[1].spin[0] 8475 8476 # The R20 keys. 8477 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8478 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8479 8480 # Printout. 8481 print("\n\nOptimised parameters:\n") 8482 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8483 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8484 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8485 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8486 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8487 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8488 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8489 8490 # Check each spin. 8491 spin_index = 0 8492 for spin, spin_id in spin_loop(return_id=True): 8493 # Printout. 8494 print("\nSpin %s." % spin_id) 8495 8496 # Check the fitted parameters. 8497 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8498 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8499 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8500 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8501 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8502 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8503 8504 # Increment the spin index. 8505 spin_index += 1
8506 8507
8508 - def test_tp02_data_to_tap03(self):
8509 """Test the dispersion 'TAP03' model fitting against the 'TP02' test data.""" 8510 8511 # Fixed time variable and the models. 8512 ds.fixed = True 8513 ds.models = ['R2eff', 'TAP03'] 8514 8515 # Execute the script. 8516 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8517 8518 # Switch back to the data pipe for the optimisation. 8519 self.interpreter.pipe.switch('TAP03 - relax_disp') 8520 8521 # The equivalent TAP03 parameters. 8522 r1rho_prime = [[10.0058156589442, 15.005818505006], [12.0766046472748, 18.076648462452]] 8523 pA = [0.775042569092891, 0.500000000229685] 8524 kex = [1235.20852748765, 2379.47085580169] 8525 delta_omega = [7.08176806468445, 5.40708372863538] 8526 chi2 = [0.0371366837083293, 0.182212857256044] 8527 8528 # Alias the spins. 8529 spin1 = cdp.mol[0].res[0].spin[0] 8530 spin2 = cdp.mol[0].res[1].spin[0] 8531 8532 # The R20 keys. 8533 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8534 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8535 8536 # Printout. 8537 print("\n\nOptimised parameters:\n") 8538 print("%-20s %-20s %-20s" % ("Parameter", "Value (:1)", "Value (:2)")) 8539 print("%-20s %20.15g %20.15g" % ("R2 (500 MHz)", spin1.r2[r20_key1], spin2.r2[r20_key1])) 8540 print("%-20s %20.15g %20.15g" % ("R2 (800 MHz)", spin1.r2[r20_key2], spin2.r2[r20_key2])) 8541 print("%-20s %20.15g %20.15g" % ("pA", spin1.pA, spin2.pA)) 8542 print("%-20s %20.15g %20.15g" % ("dw", spin1.dw, spin2.dw)) 8543 print("%-20s %20.15g %20.15g" % ("kex", spin1.kex, spin2.kex)) 8544 print("%-20s %20.15g %20.15g\n" % ("chi2", spin1.chi2, spin2.chi2)) 8545 8546 # Switch to the 'MP05' model data pipe, then check for each spin. 8547 self.interpreter.pipe.switch('TAP03 - relax_disp') 8548 spin_index = 0 8549 for spin, spin_id in spin_loop(return_id=True): 8550 # Printout. 8551 print("\nSpin %s." % spin_id) 8552 8553 # Check the fitted parameters. 8554 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8555 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8556 self.assertAlmostEqual(spin.pA, pA[spin_index], 3) 8557 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8558 self.assertAlmostEqual(spin.kex/1000.0, kex[spin_index]/1000.0, 3) 8559 self.assertAlmostEqual(spin.chi2, chi2[spin_index], 3) 8560 8561 # Increment the spin index. 8562 spin_index += 1
8563 8564
8566 """Implementation of Task #7882 U{https://gna.org/task/?7882}: Implement Monte-Carlo simulation, where errors are generated with width of standard deviation or residuals""" 8567 8568 # First check that results are stored with minimisation, to make sure that Sum of Squares are stored (Chi2 without weighting) and degrees of freedom (dof) is stored. 8569 8570 # Load the results file from a clustered minimisation. 8571 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8572 self.interpreter.results.read(file_name) 8573 8574 # Get the spins, which was used for clustering. 8575 spins_cluster = cdp.clustering['sel'] 8576 spins_free = cdp.clustering['free spins'] 8577 8578 # For sanity check, calculate degree of freedom. 8579 cur_spin_id = spins_cluster[0] 8580 cur_spin = return_spin(cur_spin_id) 8581 8582 # Calculate total number of datapoins. 8583 N = len(spins_cluster) 8584 N_dp = N * len(cur_spin.r2eff) 8585 8586 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8587 N_par = cdp.spectrometer_frq_count * N + N + 1 + 1 8588 dof = N_dp - N_par 8589 8590 # Sanity check of parameters. 8591 print(N_par, N_dp) 8592 8593 # Number of MC 8594 mc_nr = 3 8595 8596 # Setup MC for errors generated from the distribution described by chi2 and degrees of freedom from best fit. 8597 self.interpreter.monte_carlo.setup(number=mc_nr) 8598 8599 # Create data. 8600 self.interpreter.monte_carlo.create_data(distribution="red_chi2") 8601 8602 # Setup MC again. 8603 self.interpreter.monte_carlo.setup(number=mc_nr) 8604 8605 # Create data, and set the fixed error value, without setting the correct distribution. 8606 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, fixed_error=1.) 8607 8608 # Setup MC again. 8609 self.interpreter.monte_carlo.setup(number=mc_nr) 8610 8611 # Create data, with fixed error distribution, but not setting the error value. 8612 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="fixed") 8613 8614 # Setup MC again. 8615 self.interpreter.monte_carlo.create_data(distribution="fixed", fixed_error=1.) 8616 8617 # Now select the R2eff model, and try again. Expect raising an error. 8618 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 8619 8620 # Setup MC again. 8621 self.interpreter.monte_carlo.setup(number=mc_nr) 8622 8623 # Create data, and assert failure. 8624 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, distribution="red_chi2") 8625 self.assertRaises(RelaxError, self.interpreter.monte_carlo.create_data, method="direct", distribution="red_chi2")
8626 8627
8628 - def x_test_task_7882_kex_conf(self):
8629 """Test related to Task #7882 U{https://gna.org/task/?7882}: Try making a confidence interval of kex. 8630 According to the regression book of Graphpad: U{http://www.graphpad.com/faq/file/Prism4RegressionBook.pdf}. 8631 Page 109-111. 8632 """ 8633 8634 # Load the results file from a clustered minimisation. 8635 file_name = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'error_testing'+sep+'task_7882' 8636 self.interpreter.results.read(file_name) 8637 8638 # Get the spins, which was used for clustering. 8639 spins_cluster = cdp.clustering['sel'] 8640 spins_free = cdp.clustering['free spins'] 8641 8642 # For sanity check, calculate degree of freedom. 8643 cur_spin_id = spins_cluster[0] 8644 cur_spin = return_spin(cur_spin_id) 8645 8646 # Calculate total number of datapoins. 8647 Ns = len(spins_cluster) 8648 N_dp = Ns * len(cur_spin.r2eff) 8649 8650 # Calculate number of paramaters. For CR72, there is R2 per spectrometer field, individual dw, and shared kex and pA. 8651 N_par = cdp.spectrometer_frq_count * Ns + Ns + 1 + 1 8652 dof_fit = N_dp - N_par 8653 8654 # Assert values. 8655 self.assertEqual(Ns, 61) 8656 self.assertEqual(N_dp, 1952) 8657 self.assertEqual(N_par, 185) 8658 8659 # Confidence interval of kex. 8660 # The number of parameters to check is kex = 1. 8661 P = 1 8662 # Number of datapoints 8663 N = N_dp 8664 # The degrees of freedom for this confidence interval 8665 dof_conf = N - P 8666 8667 # The critical value of the F distribution with p-value of 0.05 for 95% confidence. 8668 # Can be calculated with microsoft excel: 8669 # F=FINV(0,05; P; dof_conf), F=FINV(0,05; P; dof_conf), F=FINV(0,05; 1; 1951)=3,846229551 8670 # Can also be calculated with: import scipy.stats; scipy.stats.f.isf(0.05, 1, 1951)=3.8462295505435562 8671 F = 3.8462295505435562 8672 # Then calculate the scaling of chi2, which is the weighted sum of squares of best fit. 8673 scale = F*P/dof_conf +1 8674 8675 # Get the sum of best fit. 8676 SSbest_fit = cur_spin.chi2 8677 SSbest_kex = cur_spin.kex 8678 8679 # Get the scaled sum of best fit 8680 SSall_fixed = SSbest_fit * scale 8681 8682 print(SSbest_fit, scale, SSall_fixed) 8683 8684 # Now generate a list of kex values to try. 8685 kex_cur = cur_spin.kex 8686 kex_list = linspace(kex_cur - 1500, kex_cur + 3000, 200) 8687 8688 chi2_list = [] 8689 8690 for kex in kex_list: 8691 self.interpreter.value.set(val=kex, param='kex') 8692 8693 # Calculate the chi2 values. 8694 self.interpreter.minimise.calculate(verbosity=0) 8695 8696 # Get the chi2 value 8697 chi2_cur = cur_spin.chi2 8698 print("kex=%3.2f, chi2=%3.2f"%(kex, chi2_cur), chi2_cur<SSall_fixed) 8699 8700 # Add to list 8701 chi2_list.append(chi2_cur) 8702 8703 # Now make to numpy array. 8704 chi2_list = asarray(chi2_list) 8705 8706 # Now make a selection mask based on the criteria. 8707 sel_mask = chi2_list < SSall_fixed 8708 8709 # Select values of kex, and chi2_list 8710 kex_sel = kex_list[sel_mask] 8711 chi2_sel = chi2_list[sel_mask] 8712 8713 # Now make plot 8714 print(SSbest_kex, SSbest_fit, SSall_fixed) 8715 print(kex_sel) 8716 print(chi2_sel) 8717 8718 if True: 8719 import matplotlib.pyplot as plt 8720 8721 plt.plot(kex_sel, chi2_sel, "bo") 8722 plt.plot(SSbest_kex, SSbest_fit, "g*") 8723 plt.show()
8724 8725
8726 - def test_tp02_data_to_tp02(self):
8727 """Test the relaxation dispersion 'TP02' model curve fitting to fixed time synthetic data.""" 8728 8729 # Fixed time variable. 8730 ds.fixed = True 8731 8732 # Execute the script. 8733 self.interpreter.run(script_file=status.install_path + sep+'test_suite'+sep+'system_tests'+sep+'scripts'+sep+'relax_disp'+sep+'r1rho_off_res_tp02.py') 8734 8735 # The original parameters. 8736 r1rho_prime = [[10.0, 15.0], [12.0, 18.0]] 8737 pA = 0.7654321 8738 kex = 1234.56789 8739 delta_omega = [7.0, 9.0] 8740 8741 # The R20 keys. 8742 r20_key1 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=500e6) 8743 r20_key2 = generate_r20_key(exp_type=EXP_TYPE_R1RHO, frq=800e6) 8744 8745 # Switch to the 'TP02' model data pipe, then check for each spin. 8746 self.interpreter.pipe.switch('TP02 - relax_disp') 8747 spin_index = 0 8748 for spin, spin_id in spin_loop(return_id=True): 8749 # Printout. 8750 print("\nSpin %s." % spin_id) 8751 8752 # Check the fitted parameters. 8753 self.assertAlmostEqual(spin.r2[r20_key1]/10, r1rho_prime[spin_index][0]/10, 4) 8754 self.assertAlmostEqual(spin.r2[r20_key2]/10, r1rho_prime[spin_index][1]/10, 4) 8755 self.assertAlmostEqual(spin.dw, delta_omega[spin_index], 3) 8756 self.assertAlmostEqual(spin.kex/1000.0, kex/1000.0, 3) 8757 8758 # Increment the spin index. 8759 spin_index += 1
8760 8761
8763 """System test of the value.write function to write intensities for an R1rho setup. 8764 This system test is to make sure, that modifying the API for special parameters theta and w_eff does not alter the functionality value.write. 8765 8766 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8767 """ 8768 8769 # Load the state. 8770 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8771 self.interpreter.state.load(statefile, force=True) 8772 8773 # Set filepaths. 8774 int_filepath = ds.tmpdir+sep+'int.out' 8775 8776 # Write out the intensity parameter file. 8777 # The writing out of intensity file is to make sure the API function retains its function after modification for special parameters. 8778 self.interpreter.value.write(param='peak_intensity', file='int.out', dir=ds.tmpdir, scaling=1.0, force=True) 8779 8780 # Test the file exists. 8781 self.assert_(access(int_filepath, F_OK)) 8782 8783 # Open the files for testing. 8784 int_file = open(int_filepath, 'r') 8785 8786 # Loop over the intensity file to test values. 8787 for line in int_file: 8788 # Skip lines starting with #. 8789 if line[0] == "#": 8790 continue 8791 8792 # Split the line 8793 linesplit = line.split() 8794 8795 # Assume values 8796 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8797 self.assertEqual(linesplit[5], "115571.4") 8798 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8799 self.assertEqual(linesplit[5], "68377.52") 8800 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8801 self.assertEqual(linesplit[5], "9141.689") 8802 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8803 self.assertEqual(linesplit[5], "29123.77") 8804 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8805 self.assertEqual(linesplit[5], "58914.94") 8806 8807 # Close files 8808 int_file.close()
8809 8810
8812 """System test of the value.write function to write return values of theta from calc_rotating_frame_params() function for an R1rho setup. 8813 8814 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8815 """ 8816 8817 # Load the state. 8818 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8819 self.interpreter.state.load(statefile, force=True) 8820 8821 # Set filepaths. 8822 theta_filepath = ds.tmpdir+sep+'theta.out' 8823 8824 # Write out the theta parameter file. 8825 self.interpreter.value.write(param='theta', file='theta.out', dir=ds.tmpdir, scaling=1.0, force=True) 8826 8827 # Test the file exists. 8828 self.assert_(access(theta_filepath, F_OK)) 8829 8830 # Open the files for testing. 8831 theta_file = open(theta_filepath, 'r') 8832 8833 # Loop over the theta file to test values. 8834 for line in theta_file: 8835 # Skip lines starting with #. 8836 if line[0] == "#": 8837 continue 8838 # Print lines, not including newline character. 8839 print(line[:-1]) 8840 8841 # Split the line 8842 linesplit = line.split() 8843 8844 # Assume values 8845 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8846 self.assertNotEqual(linesplit[5], "None") 8847 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8848 self.assertNotEqual(linesplit[5], "None") 8849 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8850 self.assertNotEqual(linesplit[5], "None") 8851 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8852 self.assertNotEqual(linesplit[5], "None") 8853 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8854 self.assertNotEqual(linesplit[5], "None") 8855 8856 # Close files 8857 theta_file.close()
8858 8859
8861 """System test of the value.write function to write return values of w_eff from calc_rotating_frame_params() function for an R1rho setup. 8862 8863 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8864 """ 8865 8866 # Load the state. 8867 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344_trunc.bz2' 8868 self.interpreter.state.load(statefile, force=True) 8869 8870 # Set filepaths. 8871 w_eff_filepath = ds.tmpdir+sep+'w_eff.out' 8872 8873 # Write out the w_eff parameter file. 8874 self.interpreter.value.write(param='w_eff', file='w_eff.out', dir=ds.tmpdir, scaling=1.0, force=True) 8875 8876 # Test the file exists. 8877 self.assert_(access(w_eff_filepath, F_OK)) 8878 8879 # Open the files for testing. 8880 w_eff_file = open(w_eff_filepath, 'r') 8881 8882 # Loop over the w_eff file to test values. 8883 for line in w_eff_file: 8884 # Skip lines starting with #. 8885 if line[0] == "#": 8886 continue 8887 # Print lines, not including newline character. 8888 print(line[:-1]) 8889 8890 # Split the line 8891 linesplit = line.split() 8892 8893 # Assume values 8894 if linesplit[0] == "None" and linesplit[1] == "5" and linesplit[2] == "I": 8895 self.assertNotEqual(linesplit[5], "None") 8896 elif linesplit[0] == "None" and linesplit[1] == "6" and linesplit[2] == "S": 8897 self.assertNotEqual(linesplit[5], "None") 8898 elif linesplit[0] == "None" and linesplit[1] == "8" and linesplit[2] == "S": 8899 self.assertNotEqual(linesplit[5], "None") 8900 elif linesplit[0] == "None" and linesplit[1] == "9" and linesplit[2] == "A": 8901 self.assertNotEqual(linesplit[5], "None") 8902 elif linesplit[0] == "None" and linesplit[1] == "10" and linesplit[2] == "L": 8903 self.assertNotEqual(linesplit[5], "None") 8904 8905 # Close files 8906 w_eff_file.close()
8907 8908
8910 """System test of the auto_analysis value.write function to write theta and w_eff values for an R1rho setup. 8911 8912 This uses the data of the saved state attached to U{bug #21344<https://gna.org/bugs/?21344>}. 8913 """ 8914 8915 # Load the state. 8916 statefile = status.install_path+sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'bug_21344.bz2' 8917 self.interpreter.state.load(statefile, force=True) 8918 8919 # Set pipe name, bundle and type. 8920 pipe_name = 'base pipe' 8921 pipe_bundle = 'relax_disp' 8922 pipe_type = 'relax_disp' 8923 8924 # The path to the data files. 8925 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013' 8926 8927 # Deselect all spins 8928 self.interpreter.deselect.all() 8929 8930 # Specify spins to be selected. 8931 select_spin_ids = [ 8932 ":13@N", 8933 ":15@N", 8934 ":16@N", 8935 ":25@N", 8936 ":26@N", 8937 ":28@N", 8938 ":39@N", 8939 ":40@N", 8940 ":41@N", 8941 ":43@N", 8942 ":44@N", 8943 ":45@N", 8944 ":49@N", 8945 ":52@N", 8946 ":53@N"] 8947 8948 # Reverse the selection for the spins. 8949 for curspin in select_spin_ids: 8950 print("Selecting spin %s"%curspin) 8951 self.interpreter.deselect.reverse(spin_id=curspin) 8952 8953 # Read the R1 data 8954 self.interpreter.relax_data.read(ri_id='R1', ri_type='R1', frq=cdp.spectrometer_frq_list[0], file='R1_fitted_values.txt', dir=data_path, mol_name_col=1, res_num_col=2, res_name_col=3, spin_num_col=4, spin_name_col=5, data_col=6, error_col=7) 8955 8956 # The dispersion models. 8957 MODELS = ['R2eff'] 8958 8959 # The grid search size (the number of increments per dimension). 8960 GRID_INC = 4 8961 8962 # The number of Monte Carlo simulations to be used for error analysis at the end of the analysis. 8963 MC_NUM = 3 8964 8965 # Model selection technique. 8966 MODSEL = 'AIC' 8967 8968 # Execute the auto-analysis (fast). 8969 # Standard parameters are: func_tol = 1e-25, grad_tol = None, max_iter = 10000000, 8970 OPT_FUNC_TOL = 1e-1 8971 relax_disp.Relax_disp.opt_func_tol = OPT_FUNC_TOL 8972 OPT_MAX_ITERATIONS = 1000 8973 relax_disp.Relax_disp.opt_max_iterations = OPT_MAX_ITERATIONS 8974 8975 # Run the analysis. 8976 relax_disp.Relax_disp(pipe_name=pipe_name, pipe_bundle=pipe_bundle, results_dir=ds.tmpdir, models=MODELS, grid_inc=GRID_INC, mc_sim_num=MC_NUM, modsel=MODSEL) 8977 8978 ## Check for file creation 8979 # Set filepaths. 8980 theta_filepath = ds.tmpdir+sep+MODELS[0]+sep+'theta.out' 8981 w_eff_filepath = ds.tmpdir+sep+MODELS[0]+sep+'w_eff.out' 8982 8983 # Test the files exists. 8984 self.assert_(access(theta_filepath, F_OK)) 8985 self.assert_(access(w_eff_filepath, F_OK)) 8986 8987 # Open the files for testing. 8988 theta_file = open(theta_filepath, 'r') 8989 theta_result = [ 8990 "# Parameter description: Rotating frame tilt angle : ( theta = arctan(w_1 / Omega) ) (rad).\n", 8991 "#\n", 8992 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 8993 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8994 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8995 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8996 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8997 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8998 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 8999 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9000 "None 13 L None N 1.83827367612531 None 1.79015307643158 None 2.2768687598681 None 2.08461171779445 None 2.00120623474388 None 1.92825070277699 None 1.47212860033516 None 1.12978017906854 None 1.20415336139956 None 0.901691390796334 None 0.687390207543568 None 0.455635480573046 None 0.281637123971289 None 0.138259661766539 None \n", 9001 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9002 "None 15 R None N 1.58367544790673 None 1.58127411936947 None 1.61085209029811 None 1.59731540507347 None 1.59237108385522 None 1.58834866344307 None 1.2251048782537 None 0.938142786712004 None 1.03297495592991 None 0.683284686224254 None 0.594447788256641 None 0.383528609383686 None 0.262780814059893 None 0.133469839450564 None \n", 9003 "None 16 T None N 1.40984232256624 None 1.43947245672073 None 1.10299856647417 None 1.24811470332083 None 1.30521602599932 None 1.35302443831853 None 1.07923777467974 None 0.833345927788896 None 0.934350308974616 None 0.581325254389991 None 0.543659670184793 None 0.346238480454282 None 0.251454336191817 None 0.130436714663781 None \n", 9004 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9005 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9006 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9007 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9008 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9009 "None 25 Q None N 1.81569700258844 None 1.77137827615015 None 2.23175875585624 None 2.04612705363098 None 1.9673155780155 None 1.89908711012298 None 1.44829660124856 None 1.11023386429581 None 1.18716091371256 None 0.877306975624962 None 0.677790118853413 None 0.447932002242236 None 0.279785379050945 None 0.137802891887767 None \n", 9010 "None 26 Q None N 1.61128821168674 None 1.60374392042003 None 1.69619923953765 None 1.65403989292986 None 1.63856717205868 None 1.62595755714564 None 1.24977859227795 None 0.956353494917591 None 1.04972090035774 None 0.702164059520172 None 0.603227813742091 None 0.390116910781037 None 0.264658552037535 None 0.133960994297096 None \n", 9011 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9012 "None 28 Q None N 1.65182797011356 None 1.63676707684161 None 1.81830827892972 None 1.7365089711986 None 1.70601955220877 None 1.68102938663686 None 1.28685736157369 None 0.984047498595701 None 1.0749792109454 None 0.731585685663053 None 0.616577997665602 None 0.400219205533665 None 0.267471993812649 None 0.134690869499646 None \n", 9013 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9014 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9015 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9016 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9017 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9018 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9019 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9020 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9021 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9022 "None 39 L None N 1.76426439181176 None 1.72885318885161 None 2.11826300085737 None 1.95430201082222 None 1.88794717058464 None 1.83172922971397 None 1.39549951193417 None 1.06783946148624 None 1.14997013232702 None 0.826128785942585 None 0.657105386950171 None 0.431542911580536 None 0.275725736430539 None 0.136791385554619 None \n", 9023 "None 40 M None N 1.5521741199158 None 1.55564594516135 None 1.51290906497298 None 1.53245929150759 None 1.53960430408466 None 1.54541832596591 None 1.19750223001929 None 0.917959090226757 None 1.01428385962747 None 0.662779584695967 None 0.584708929219264 None 0.376271266885303 None 0.260671619214194 None 0.132914250767089 None \n", 9024 "None 41 A None N 1.68339451828261 None 1.66252964414082 None 1.90911961276946 None 1.79959323497326 None 1.75801925517113 None 1.72370710837265 None 1.31646868936419 None 1.00647189763597 None 1.09525348649914 None 0.75605702767542 None 0.627395557358039 None 0.408481831044309 None 0.269716174238842 None 0.135267948387412 None \n", 9025 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9026 "None 43 F None N 1.58506597154432 None 1.58240542750303 None 1.61517196062351 None 1.60017740004898 None 1.59469990835425 None 1.59024353162528 None 1.22633651794829 None 0.939047922181951 None 1.03380990731605 None 0.684214484755514 None 0.594884298549546 None 0.383855128702894 None 0.262874695048502 None 0.13349447283116 None \n", 9027 "None 44 I None N 1.57575471961837 None 1.57483015671791 None 1.58622388390755 None 1.58100758841935 None 1.57910319967536 None 1.57755415552211 None 1.21811077066835 None 0.933010299763027 None 1.02823520295828 None 0.67802911457195 None 0.591972285081647 None 0.381678892926696 None 0.262247347241724 None 0.133329708422379 None \n", 9028 "None 45 K None N 1.77147501495754 None 1.73479633022489 None 2.13509660780385 None 1.96751045408372 None 1.89924480319914 None 1.84124387452692 None 1.40277881643715 None 1.07361367582571 None 1.15506365550891 None 0.832963505534767 None 0.659913187081268 None 0.433751178249555 None 0.276282572106685 None 0.13693095791902 None \n", 9029 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9030 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9031 "None 49 A None N 2.00297059962685 None 1.92978318052058 None 2.53305709323468 None 2.33052197276846 None 2.22870514722639 None 2.13201782446864 None 1.6587904412969 None 1.29333162369472 None 1.34311052758116 None 1.12559033900783 None 0.770195063841652 None 0.524846264860003 None 0.296857751274362 None 0.141908833673671 None \n", 9032 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9033 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9034 "None 52 V None N 1.82421571143794 None 1.77845404105203 None 2.24910726268822 None 2.06078232916932 None 1.98017451806059 None 1.91012195713554 None 1.45724107606646 None 1.11753869321304 None 1.19352234944057 None 0.886361068343012 None 0.681372607920812 None 0.450799407357501 None 0.280478735779163 None 0.137974257665877 None \n", 9035 "None 53 A None N 2.05019708195234 None 1.97089957318506 None 2.58789168363698 None 2.39027806684801 None 2.28731354878582 None 2.1872118539319 None 1.7165709935896 None 1.34832362477229 None 1.38879751095815 None 1.2085314357749 None 0.799450059125864 None 0.550583841461621 None 0.30195492609136 None 0.143090604877102 None \n", 9036 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9037 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9038 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9039 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9040 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9041 ] 9042 # Check the created theta file. 9043 lines = theta_file.readlines() 9044 for i in range(len(lines)): 9045 # Test lines starting with # 9046 if theta_result[i][0] == "#": 9047 self.assertEqual(theta_result[i], lines[i]) 9048 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9049 if theta_result[i] == lines[i]: 9050 self.assertEqual(theta_result[i], lines[i]) 9051 # If the line is not equal each other, make a slower comparison of values. 9052 else: 9053 # Print lines if they don't match. To help find differences. 9054 print(theta_result[i]) 9055 print(lines[i]) 9056 9057 # First test first 62 characters containing spin information 9058 self.assertEqual(theta_result[i][:62], lines[i][:62]) 9059 9060 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9061 theta_result_s = theta_result[i][62:].split()[::2] 9062 print(theta_result_s ) 9063 lines_s = lines[i][62:].split()[::2] 9064 print(lines_s) 9065 # Loop over the value elements 9066 for j in range(len(lines_s)): 9067 print(theta_result_s[j], lines_s[j]) 9068 # Assume a precision to digits. 9069 self.assertAlmostEqual(float(theta_result_s[j]), float(lines_s[j]), 14) 9070 9071 # Close file 9072 theta_file.close() 9073 9074 w_eff_file = open(w_eff_filepath, 'r') 9075 w_eff_result = [ 9076 "# Parameter description: Effective field in rotating frame : ( w_eff = sqrt(Omega^2 + w_1^2) ) (rad.s^-1).\n", 9077 "#\n", 9078 "# mol_name res_num res_name spin_num spin_name r1rho_799.77739910_118.078_1341.110 sd(r1rho_799.77739910_118.078_1341.110) r1rho_799.77739910_118.078_1648.500 sd(r1rho_799.77739910_118.078_1648.500) r1rho_799.77739910_118.078_431.000 sd(r1rho_799.77739910_118.078_431.000) r1rho_799.77739910_118.078_651.200 sd(r1rho_799.77739910_118.078_651.200) r1rho_799.77739910_118.078_800.500 sd(r1rho_799.77739910_118.078_800.500) r1rho_799.77739910_118.078_984.000 sd(r1rho_799.77739910_118.078_984.000) r1rho_799.77739910_124.247_1341.110 sd(r1rho_799.77739910_124.247_1341.110) r1rho_799.77739910_130.416_1341.110 sd(r1rho_799.77739910_130.416_1341.110) r1rho_799.77739910_130.416_1648.500 sd(r1rho_799.77739910_130.416_1648.500) r1rho_799.77739910_130.416_800.500 sd(r1rho_799.77739910_130.416_800.500) r1rho_799.77739910_142.754_1341.110 sd(r1rho_799.77739910_142.754_1341.110) r1rho_799.77739910_142.754_800.500 sd(r1rho_799.77739910_142.754_800.500) r1rho_799.77739910_179.768_1341.110 sd(r1rho_799.77739910_179.768_1341.110) r1rho_799.77739910_241.459_1341.110 sd(r1rho_799.77739910_241.459_1341.110) \n", 9079 "None 5 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9080 "None 6 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9081 "None 8 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9082 "None 9 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9083 "None 10 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9084 "None 11 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9085 "None 12 D None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9086 "None 13 L None N 8737.12883908829 None 10612.1226552258 None 3558.93734069587 None 4698.27194621826 None 5534.46153956037 None 6599.82570817753 None 8467.62674839481 None 9318.00441649087 None 11095.2662520767 None 6412.33580591254 None 13279.9803044242 None 11430.254637056 None 30318.7268264644 None 61141.1080046448 None \n", 9087 "None 14 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9088 "None 15 R None N 8427.14155005377 None 10358.3995676635 None 2710.22680763322 None 4093.04942975722 None 5030.86065069262 None 6183.60685459024 None 8956.28403254202 None 10448.6627754369 None 12060.4428066937 None 7966.64282975241 None 15045.8392092364 None 13441.3586252373 None 32438.4764809909 None 63321.5201471181 None \n", 9089 "None 16 T None N 8536.7818857229 None 10447.792678989 None 3034.01707453628 None 4314.2767521567 None 5212.43600885913 None 6332.21319855067 None 9558.14311447582 None 11384.2336494604 None 12879.4604966293 None 9159.34604475399 None 16290.1746838959 None 14821.0200530829 None 33866.5933527757 None 64785.3205696403 None \n", 9090 "None 17 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9091 "None 18 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9092 "None 19 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9093 "None 21 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9094 "None 24 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9095 "None 25 Q None N 8685.60895531182 None 10569.7459677762 None 3430.51272680396 None 4601.75421490393 None 5452.76508815826 None 6531.46859076009 None 8490.06475886501 None 9406.58372902508 None 11169.7602637607 None 6540.38696356753 None 13437.7348017798 None 11613.1632549021 None 30514.0741594726 None 61342.4792156782 None \n", 9096 "None 26 Q None N 8433.35533683544 None 10363.4554631194 None 2729.48656005151 None 4105.82770792005 None 5041.26238350827 None 6192.07245313098 None 8880.08366342131 None 10312.6868786802 None 11942.8320576165 None 7787.44854491812 None 14853.4987024375 None 13225.7048162038 None 32213.6690023282 None 63090.7407990801 None \n", 9097 "None 27 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9098 "None 28 Q None N 8454.18308422202 None 10380.4112885894 None 2793.17494362899 None 4148.43953208179 None 5076.02756135055 None 6220.40920270029 None 8777.91538040813 None 10118.8737706315 None 11775.8792998529 None 7528.90766101027 None 14572.4015102398 None 12909.211050939 None 31882.8171856889 None 62750.9120842199 None \n", 9099 "None 29 V None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9100 "None 30 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9101 "None 31 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9102 "None 32 I None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9103 "None 33 L None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9104 "None 34 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9105 "None 35 S None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9106 "None 36 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9107 "None 38 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9108 "None 39 L None N 8586.6405431352 None 10488.5710521378 None 3171.59430904777 None 4412.11227722123 None 5293.69814015286 None 6399.27143075725 None 8557.58926327909 None 9617.45773774313 None 11347.9169998729 None 6840.20010813426 None 13795.1250622375 None 12024.9041436853 None 30951.651485352 None 61793.2130509111 None \n", 9109 "None 40 M None N 8427.90394711227 None 10359.0198301036 None 2712.59646573568 None 4094.61889210019 None 5032.13762965554 None 6184.6458240746 None 9049.68452800053 None 10607.7913029633 None 12198.5639821231 None 8174.23271685285 None 15266.4924700447 None 13687.9010998756 None 32694.9043143038 None 63584.6371927381 None \n", 9110 "None 41 A None N 8480.14299737436 None 10401.5648897003 None 2870.79081440785 None 4201.09083283266 None 5119.14733505123 None 6255.64579267482 None 8706.50768957471 None 9972.71017314947 None 11650.5225246067 None 7331.28858930568 None 14354.1616183112 None 12662.3378547029 None 31623.9195264738 None 62484.8290612112 None \n", 9111 "None 42 A None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9112 "None 43 F None N 8427.30062786474 None 10358.5289868368 None 2710.7214015056 None 4093.37694357637 None 5031.12711571215 None 6183.82364721878 None 8952.31975962078 None 10441.7375680915 None 12054.4435931163 None 7957.55789315654 None 15036.1316712316 None 13430.4914212645 None 32427.1596037519 None 63309.9050677925 None \n", 9113 "None 44 I None N 8426.54623319716 None 10357.9152496503 None 2708.3751705368 None 4091.82359712664 None 5029.86337809029 None 6182.79552045043 None 8979.12144335458 None 10488.2688526334 None 12094.7720286018 None 8018.51779989075 None 15101.1843990883 None 13503.2816173444 None 32502.9389163062 None 63387.6763306952 None \n", 9114 "None 45 K None N 8599.01176345321 None 10498.7013581079 None 3204.93649737055 None 4436.14046641897 None 5313.74138343704 None 6415.86177652694 None 8546.79665373249 None 9587.16245449134 None 11322.2529042385 None 6797.53838612575 None 13745.1536613763 None 11967.5433300612 None 30890.8603419261 None 61730.6213936947 None \n", 9115 "None 46 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9116 "None 48 T None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9117 "None 49 A None N 9279.63849130869 None 11063.0654625247 None 4737.11992391463 None 5643.40583860235 None 6356.45614406507 None 7302.87406141381 None 8459.17105047661 None 8761.54554569995 None 10632.2343488142 None 5572.92782399155 None 12102.1714908775 None 10037.6988885228 None 28806.6916858172 None 59579.0348769179 None \n", 9118 "None 50 K None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9119 "None 51 Y None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9120 "None 52 V None N 8704.45610117774 None 10585.2389163429 None 3477.9549539207 None 4637.22923167743 None 5482.73656118686 None 6556.5108895527 None 8481.06470969555 None 9372.86414918436 None 11141.3782476763 None 6491.79686536093 None 13378.2843939736 None 11544.3205736882 None 30440.62308788 None 61266.7742546508 None \n", 9121 "None 53 A None N 9497.02860450276 None 11246.0339326126 None 5149.96766581255 None 5994.15475647208 None 6669.81232845336 None 7577.19152075731 None 8516.77431951689 None 8639.36099840319 None 10531.7750336522 None 5378.79193153767 None 11752.8060152439 None 9613.59939949642 None 28334.9153747994 None 59090.2988815445 None \n", 9122 "None 54 N None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9123 "None 55 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9124 "None 57 G None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9125 "None 58 M None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n", 9126 "None 59 Q None N None None None None None None None None None None None None None None None None None None None None None None None None None None None None \n" 9127 ] 9128 # Check the created w_eff file. 9129 lines = w_eff_file.readlines() 9130 for i in range(len(lines)): 9131 # Test lines starting with # 9132 if w_eff_result[i][0] == "#": 9133 self.assertEqual(w_eff_result[i], lines[i]) 9134 # If the line is equal each other, make a line comparison. This should catch lines with None values. 9135 if w_eff_result[i] == lines[i]: 9136 self.assertEqual(w_eff_result[i], lines[i]) 9137 # If the line is not equal each other, make a slower comparison of values. 9138 else: 9139 # Print lines if they don't match. To help find differences. 9140 print(w_eff_result[i]) 9141 print(lines[i]) 9142 9143 # First test first 62 characters containing spin information 9144 self.assertEqual(w_eff_result[i][:62], lines[i][:62]) 9145 9146 # Make a string split after 62 characters. Select each second element, so None values are skipped. 9147 w_eff_result_s = w_eff_result[i][62:].split()[::2] 9148 print(w_eff_result_s ) 9149 lines_s = lines[i][62:].split()[::2] 9150 print(lines_s) 9151 # Loop over the value elements 9152 for j in range(len(lines_s)): 9153 print(w_eff_result_s[j], lines_s[j]) 9154 # Assume a precision to digits. 9155 self.assertAlmostEqual(float(w_eff_result_s[j]), float(lines_s[j]), 14) 9156 9157 # Close file 9158 w_eff_file.close()
9159 9160
9162 """Test the user function for estimating R2eff errors from exponential curve fitting, and compare it with Monte-Carlo simulations. 9163 9164 This follows Task 7822. 9165 U{task #7822<https://gna.org/task/index.php?7822>}: Implement user function to estimate R2eff and associated errors for exponential curve fitting. 9166 9167 This uses the data from Kjaergaard's paper at U{DOI: 10.1021/bi4001062<http://dx.doi.org/10.1021/bi4001062>}. 9168 Optimisation of the Kjaergaard et al., 2013 Off-resonance R1rho relaxation dispersion experiments using the 'DPL' model. 9169 """ 9170 9171 # Load the data. 9172 data_path = status.install_path + sep+'test_suite'+sep+'shared_data'+sep+'dispersion'+sep+'Kjaergaard_et_al_2013'+sep 9173 9174 # Set pipe name, bundle and type. 9175 pipe_name = 'base pipe' 9176 pipe_bundle = 'relax_disp' 9177 pipe_type = 'relax_disp' 9178 9179 # Create the data pipe. 9180 self.interpreter.pipe.create(pipe_name=pipe_name, bundle=pipe_bundle, pipe_type=pipe_type) 9181 9182 file = data_path + '1_setup_r1rho_GUI.py' 9183 self.interpreter.script(file=file, dir=None) 9184 9185 # Deselect all spins. 9186 self.interpreter.deselect.spin(spin_id=':1-100', change_all=False) 9187 9188 # Select one spin. 9189 self.interpreter.select.spin(spin_id=':52@N', change_all=False) 9190 9191 # Set the model. 9192 self.interpreter.relax_disp.select_model(MODEL_R2EFF) 9193 9194 # Check if intensity errors have already been calculated. 9195 check_intensity_errors() 9196 9197 # Do a grid search. 9198 self.interpreter.minimise.grid_search(lower=None, upper=None, inc=11, constraints=True, verbosity=1) 9199 9200 # Set algorithm. 9201 min_algor = 'Newton' 9202 constraints = True 9203 if constraints: 9204 min_options = ('%s'%(min_algor),) 9205 #min_algor = 'Log barrier' 9206 min_algor = 'Method of Multipliers' 9207 scaling_matrix = assemble_scaling_matrix(scaling=True) 9208 9209 # Collect spins 9210 all_spin_ids = [] 9211 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9212 all_spin_ids.append(spin_id) 9213 9214 spins = spin_ids_to_containers(all_spin_ids[:1]) 9215 9216 # Get constraints 9217 A, b = linear_constraints(spins=spins, scaling_matrix=scaling_matrix[0]) 9218 else: 9219 min_options = () 9220 A, b = None, None 9221 min_options = () 9222 sim_boot = 200 9223 scaling_list = [1.0, 1.0] 9224 9225 # Minimise. 9226 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints, verbosity=1) 9227 9228 # Loop over old err attributes. 9229 err_attr_list = ['r2eff_err', 'i0_err'] 9230 9231 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9232 # Loop over old err attributes. 9233 for err_attr in err_attr_list: 9234 if hasattr(cur_spin, err_attr): 9235 delattr(cur_spin, err_attr) 9236 9237 # Collect the estimation data from boot. 9238 my_dic = {} 9239 param_key_list = [] 9240 est_keys = [] 9241 est_key = '-2' 9242 est_keys.append(est_key) 9243 spin_id_list = [] 9244 9245 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9246 # Add key to dic. 9247 my_dic[spin_id] = {} 9248 9249 # Add key for estimate. 9250 my_dic[spin_id][est_key] = {} 9251 9252 # Add spin key to list. 9253 spin_id_list.append(spin_id) 9254 9255 # Generate spin string. 9256 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9257 9258 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9259 # Generate the param_key. 9260 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9261 9262 # Append key. 9263 param_key_list.append(param_key) 9264 9265 # Add key to dic. 9266 my_dic[spin_id][est_key][param_key] = {} 9267 9268 values = [] 9269 errors = [] 9270 times = [] 9271 for time in loop_time(exp_type=exp_type, frq=frq, offset=offset, point=point): 9272 values.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time)) 9273 errors.append(average_intensity(spin=cur_spin, exp_type=exp_type, frq=frq, offset=offset, point=point, time=time, error=True)) 9274 times.append(time) 9275 9276 # Convert to numpy array. 9277 values = asarray(values) 9278 errors = asarray(errors) 9279 times = asarray(times) 9280 9281 r2eff = getattr(cur_spin, 'r2eff')[param_key] 9282 i0 = getattr(cur_spin, 'i0')[param_key] 9283 9284 R_m_sim_l = [] 9285 I0_m_sim_l = [] 9286 for j in range(sim_boot): 9287 if j in range(0, 100000, 100): 9288 print("Simulation %i"%j) 9289 # Start minimisation. 9290 9291 # Produce errors 9292 I_err = [] 9293 for j, error in enumerate(errors): 9294 I_error = gauss(values[j], error) 9295 I_err.append(I_error) 9296 # Convert to numpy array. 9297 I_err = asarray(I_err) 9298 9299 x0 = [r2eff, i0] 9300 model = Relax_fit_opt(num_params=len(x0), values=I_err, errors=errors, relax_times=times, scaling_matrix=scaling_list) 9301 9302 # Ref input. 9303 #def generic_minimise(func=None, dfunc=None, d2func=None, args=(), x0=None, min_algor=None, min_options=None, func_tol=1e-25, grad_tol=None, maxiter=1e6, A=None, b=None, l=None, u=None, c=None, dc=None, d2c=None, print_flag=0, print_prefix="", full_output=False): 9304 # l=l, u=u, c=c, dc=dc, d2c=d2c 9305 # l: Lower bound constraint vector (l <= x <= u). 9306 # u: Upper bound constraint vector (l <= x <= u). 9307 # c: User supplied constraint function. 9308 # dc: User supplied constraint gradient function. 9309 params_minfx_sim_j, chi2_minfx_sim_j, iter_count, f_count, g_count, h_count, warning = generic_minimise(func=model.func, dfunc=model.dfunc, d2func=model.d2func, args=(), x0=x0, min_algor=min_algor, min_options=min_options, A=A, b=b, full_output=True, print_flag=0) 9310 9311 R_m_sim_j, I0_m_sim_j = params_minfx_sim_j 9312 R_m_sim_l.append(R_m_sim_j) 9313 I0_m_sim_l.append(I0_m_sim_j) 9314 9315 # Get stats on distribution. 9316 sigma_R_sim = std(asarray(R_m_sim_l), ddof=1) 9317 sigma_I0_sim = std(asarray(I0_m_sim_l), ddof=1) 9318 my_dic[spin_id][est_key][param_key]['r2eff_err'] = sigma_R_sim 9319 my_dic[spin_id][est_key][param_key]['i0_err'] = sigma_I0_sim 9320 9321 # Estimate R2eff errors. 9322 self.interpreter.relax_disp.r2eff_err_estimate() 9323 9324 est_key = '-1' 9325 est_keys.append(est_key) 9326 9327 # Collect data. 9328 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9329 # Add key for estimate. 9330 my_dic[spin_id][est_key] = {} 9331 9332 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9333 # Generate the param_key. 9334 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9335 9336 # Add key to dic. 9337 my_dic[spin_id][est_key][param_key] = {} 9338 9339 # Get the value. 9340 # Loop over err attributes. 9341 for err_attr in err_attr_list: 9342 if hasattr(cur_spin, err_attr): 9343 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9344 else: 9345 get_err_attr = 0.0 9346 9347 # Save to dic. 9348 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9349 9350 9351 # Make Carlo Simulations number 9352 mc_number_list = list(range(0, 1000, 250)) 9353 9354 sim_attr_list = ['chi2_sim', 'f_count_sim', 'g_count_sim', 'h_count_sim', 'i0_sim', 'iter_sim', 'peak_intensity_sim', 'r2eff_sim', 'select_sim', 'warning_sim'] 9355 9356 # Loop over the Monte Carlo simulations: 9357 for number in mc_number_list: 9358 # First delete old simulations. 9359 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9360 # Loop over old err attributes. 9361 for err_attr in err_attr_list: 9362 if hasattr(cur_spin, err_attr): 9363 delattr(cur_spin, err_attr) 9364 9365 # Loop over the simulated attributes. 9366 for sim_attr in sim_attr_list: 9367 if hasattr(cur_spin, sim_attr): 9368 delattr(cur_spin, sim_attr) 9369 9370 self.interpreter.monte_carlo.setup(number=number) 9371 self.interpreter.monte_carlo.create_data() 9372 self.interpreter.monte_carlo.initial_values() 9373 self.interpreter.minimise.execute(min_algor=min_algor, constraints=constraints) 9374 self.interpreter.eliminate() 9375 self.interpreter.monte_carlo.error_analysis() 9376 9377 est_key = '%i'%number 9378 est_keys.append(est_key) 9379 9380 # Collect data. 9381 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9382 # Add key for estimate. 9383 my_dic[spin_id][est_key] = {} 9384 9385 for exp_type, frq, offset, point, ei, mi, oi, di in loop_exp_frq_offset_point(return_indices=True): 9386 # Generate the param_key. 9387 param_key = return_param_key_from_data(exp_type=exp_type, frq=frq, offset=offset, point=point) 9388 9389 # Add key to dic. 9390 my_dic[spin_id][est_key][param_key] = {} 9391 9392 # Get the value. 9393 # Loop over err attributes. 9394 for err_attr in err_attr_list: 9395 if hasattr(cur_spin, err_attr): 9396 get_err_attr = getattr(cur_spin, err_attr)[param_key] 9397 else: 9398 get_err_attr = 0.0 9399 9400 # Save to dic. 9401 my_dic[spin_id][est_key][param_key][err_attr] = get_err_attr 9402 9403 # Set what to extract. 9404 err_attr = err_attr_list[0] 9405 9406 # Define list with text. 9407 text_list = [] 9408 9409 # Now loop through the data. 9410 for spin_id in spin_id_list: 9411 for est_key in est_keys: 9412 # Define list to pickup data. 9413 r2eff_err_list = [] 9414 9415 for param_key in param_key_list: 9416 # Get the value. 9417 r2eff_err = my_dic[spin_id][est_key][param_key][err_attr] 9418 9419 # Add to list. 9420 r2eff_err_list.append(r2eff_err) 9421 9422 # Sum the list 9423 sum_array = sum(array(r2eff_err_list)) 9424 9425 # Join floats to string. 9426 r2eff_err_str = " ".join(format(x, "2.3f") for x in r2eff_err_list) 9427 9428 # Define print string. 9429 text = "%8s %s sum= %2.3f" % (est_key, r2eff_err_str, sum_array) 9430 text_list.append(text) 9431 9432 9433 # Now print. 9434 filepath = NamedTemporaryFile(delete=False).name 9435 # Open the files for testing. 9436 w_file = open(filepath, 'w') 9437 9438 print("Printing the estimated R2eff error as function of estimation from Co-variance and number of Monte-Carlo simulations.") 9439 9440 for text in text_list: 9441 # Print. 9442 print(text) 9443 9444 # Write to file. 9445 w_file.write(text+"\n") 9446 9447 # Close files 9448 w_file.close() 9449 9450 print("Filepath is: %s"%filepath) 9451 print("Start 'gnuplot' and write:") 9452 print("set term dumb") 9453 print("plot '%s' using 1:17 title 'R2eff error as function of MC number' w linespoints "%filepath)
9454 9455
9456 - def verify_r1rho_kjaergaard_missing_r1(self, models=None, result_dir_name=None, r2eff_estimate=None):
9457 """Verification of test_r1rho_kjaergaard_missing_r1.""" 9458 9459 # Check the kex value of residue 52 9460 #self.assertAlmostEqual(cdp.mol[0].res[41].spin[0].kex, ds.ref[':52@N'][6]) 9461 9462 # Print results for each model. 9463 print("\n\n################") 9464 print("Printing results") 9465 print("################\n") 9466 for model in models: 9467 # Skip R2eff model. 9468 if model == MODEL_R2EFF: 9469 continue 9470 9471 # Switch to pipe. 9472 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9473 print("\nModel: %s" % (model)) 9474 9475 # Loop over the spins. 9476 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9477 # Generate spin string. 9478 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9479 9480 # Loop over the parameters. 9481 print("Optimised parameters for spin: %s" % (spin_string)) 9482 for param in cur_spin.params + ['chi2']: 9483 # Get the value. 9484 if param in ['r1', 'r2']: 9485 for exp_type, frq, ei, mi in loop_exp_frq(return_indices=True): 9486 # Generate the R20 key. 9487 r20_key = generate_r20_key(exp_type=exp_type, frq=frq) 9488 9489 # Get the value. 9490 value = getattr(cur_spin, param)[r20_key] 9491 9492 # Print value. 9493 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9494 9495 # Compare values. 9496 if spin_id == ':52@N': 9497 if param == 'r1': 9498 if model == MODEL_NOREX: 9499 if r2eff_estimate == 'direct': 9500 self.assertAlmostEqual(value, 1.46138805) 9501 elif r2eff_estimate == 'MC2000': 9502 self.assertAlmostEqual(value, 1.46328102) 9503 elif r2eff_estimate == 'chi2_pyt': 9504 self.assertAlmostEqual(value, 1.43820629) 9505 elif model == MODEL_DPL94: 9506 if r2eff_estimate == 'direct': 9507 self.assertAlmostEqual(value, 1.44845742) 9508 elif r2eff_estimate == 'MC2000': 9509 self.assertAlmostEqual(value, 1.45019848) 9510 elif r2eff_estimate == 'chi2_pyt': 9511 self.assertAlmostEqual(value, 1.44666512) 9512 elif model == MODEL_TP02: 9513 if r2eff_estimate == 'direct': 9514 self.assertAlmostEqual(value, 1.54354392) 9515 elif r2eff_estimate == 'MC2000': 9516 self.assertAlmostEqual(value, 1.54352369) 9517 elif r2eff_estimate == 'chi2_pyt': 9518 self.assertAlmostEqual(value, 1.55964020) 9519 elif model == MODEL_TAP03: 9520 if r2eff_estimate == 'direct': 9521 self.assertAlmostEqual(value, 1.54356410) 9522 elif r2eff_estimate == 'MC2000': 9523 self.assertAlmostEqual(value, 1.54354367) 9524 elif r2eff_estimate == 'chi2_pyt': 9525 self.assertAlmostEqual(value, 1.55967157) 9526 elif model == MODEL_MP05: 9527 if r2eff_estimate == 'direct': 9528 self.assertAlmostEqual(value, 1.54356416) 9529 elif r2eff_estimate == 'MC2000': 9530 self.assertAlmostEqual(value, 1.54354372) 9531 elif r2eff_estimate == 'chi2_pyt': 9532 self.assertAlmostEqual(value, 1.55967163) 9533 elif model == MODEL_NS_R1RHO_2SITE: 9534 if r2eff_estimate == 'direct': 9535 self.assertAlmostEqual(value, 1.41359221, 5) 9536 elif r2eff_estimate == 'MC2000': 9537 self.assertAlmostEqual(value, 1.41321968, 5) 9538 elif r2eff_estimate == 'chi2_pyt': 9539 self.assertAlmostEqual(value, 1.36303129, 5) 9540 9541 elif param == 'r2': 9542 if model == MODEL_NOREX: 9543 if r2eff_estimate == 'direct': 9544 self.assertAlmostEqual(value, 11.48392439) 9545 elif r2eff_estimate == 'MC2000': 9546 self.assertAlmostEqual(value, 11.48040934) 9547 elif r2eff_estimate == 'chi2_pyt': 9548 self.assertAlmostEqual(value, 11.47224488) 9549 elif model == MODEL_DPL94: 9550 if r2eff_estimate == 'direct': 9551 self.assertAlmostEqual(value, 10.15688372, 6) 9552 elif r2eff_estimate == 'MC2000': 9553 self.assertAlmostEqual(value, 10.16304887, 6) 9554 elif r2eff_estimate == 'chi2_pyt': 9555 self.assertAlmostEqual(value, 9.20037797, 6) 9556 elif model == MODEL_TP02: 9557 if r2eff_estimate == 'direct': 9558 self.assertAlmostEqual(value, 9.72654896, 6) 9559 elif r2eff_estimate == 'MC2000': 9560 self.assertAlmostEqual(value, 9.72772726, 6) 9561 elif r2eff_estimate == 'chi2_pyt': 9562 self.assertAlmostEqual(value, 9.53948340, 6) 9563 elif model == MODEL_TAP03: 9564 if r2eff_estimate == 'direct': 9565 self.assertAlmostEqual(value, 9.72641887, 6) 9566 elif r2eff_estimate == 'MC2000': 9567 self.assertAlmostEqual(value, 9.72759374, 6) 9568 elif r2eff_estimate == 'chi2_pyt': 9569 self.assertAlmostEqual(value, 9.53926913, 6) 9570 elif model == MODEL_MP05: 9571 if r2eff_estimate == 'direct': 9572 self.assertAlmostEqual(value, 9.72641723, 6) 9573 elif r2eff_estimate == 'MC2000': 9574 self.assertAlmostEqual(value, 9.72759220, 6) 9575 elif r2eff_estimate == 'chi2_pyt': 9576 self.assertAlmostEqual(value, 9.53926778, 6) 9577 elif model == MODEL_NS_R1RHO_2SITE: 9578 if r2eff_estimate == 'direct': 9579 self.assertAlmostEqual(value, 9.34531535, 5) 9580 elif r2eff_estimate == 'MC2000': 9581 self.assertAlmostEqual(value, 9.34602793, 5) 9582 elif r2eff_estimate == 'chi2_pyt': 9583 self.assertAlmostEqual(value, 9.17631409, 5) 9584 9585 # For all other parameters. 9586 else: 9587 # Get the value. 9588 value = getattr(cur_spin, param) 9589 9590 # Print value. 9591 print("%-10s %-6s %-6s %3.8f" % ("Parameter:", param, "Value:", value)) 9592 9593 # Compare values. 9594 if spin_id == ':52@N': 9595 if param == 'phi_ex': 9596 if model == MODEL_DPL94: 9597 if r2eff_estimate == 'direct': 9598 self.assertAlmostEqual(value, 0.07599563) 9599 elif r2eff_estimate == 'MC2000': 9600 self.assertAlmostEqual(value, 0.07561937) 9601 elif r2eff_estimate == 'chi2_pyt': 9602 self.assertAlmostEqual(value, 0.12946061) 9603 9604 elif param == 'pA': 9605 if model == MODEL_TP02: 9606 if r2eff_estimate == 'direct': 9607 self.assertAlmostEqual(value, 0.88827040) 9608 elif r2eff_estimate == 'MC2000': 9609 self.assertAlmostEqual(value, 0.88807487) 9610 elif r2eff_estimate == 'chi2_pyt': 9611 self.assertAlmostEqual(value, 0.87746233) 9612 elif model == MODEL_TAP03: 9613 if r2eff_estimate == 'direct': 9614 self.assertAlmostEqual(value, 0.88828922) 9615 elif r2eff_estimate == 'MC2000': 9616 self.assertAlmostEqual(value, 0.88809318) 9617 elif r2eff_estimate == 'chi2_pyt': 9618 self.assertAlmostEqual(value, 0.87747558) 9619 elif model == MODEL_MP05: 9620 if r2eff_estimate == 'direct': 9621 self.assertAlmostEqual(value, 0.88828924, 6) 9622 elif r2eff_estimate == 'MC2000': 9623 self.assertAlmostEqual(value, 0.88809321) 9624 elif r2eff_estimate == 'chi2_pyt': 9625 self.assertAlmostEqual(value, 0.87747562) 9626 elif model == MODEL_NS_R1RHO_2SITE: 9627 if r2eff_estimate == 'direct': 9628 self.assertAlmostEqual(value, 0.94504369, 6) 9629 elif r2eff_estimate == 'MC2000': 9630 self.assertAlmostEqual(value, 0.94496541, 6) 9631 elif r2eff_estimate == 'chi2_pyt': 9632 self.assertAlmostEqual(value, 0.92084707, 6) 9633 9634 elif param == 'dw': 9635 if model == MODEL_TP02: 9636 if r2eff_estimate == 'direct': 9637 self.assertAlmostEqual(value, 1.08875840, 6) 9638 elif r2eff_estimate == 'MC2000': 9639 self.assertAlmostEqual(value, 1.08765638, 6) 9640 elif r2eff_estimate == 'chi2_pyt': 9641 self.assertAlmostEqual(value, 1.09753230, 6) 9642 elif model == MODEL_TAP03: 9643 if r2eff_estimate == 'direct': 9644 self.assertAlmostEqual(value, 1.08837238, 6) 9645 elif r2eff_estimate == 'MC2000': 9646 self.assertAlmostEqual(value, 1.08726698, 6) 9647 elif r2eff_estimate == 'chi2_pyt': 9648 self.assertAlmostEqual(value, 1.09708821, 6) 9649 elif model == MODEL_MP05: 9650 if r2eff_estimate == 'direct': 9651 self.assertAlmostEqual(value, 1.08837241, 6) 9652 elif r2eff_estimate == 'MC2000': 9653 self.assertAlmostEqual(value, 1.08726706, 6) 9654 elif r2eff_estimate == 'chi2_pyt': 9655 self.assertAlmostEqual(value, 1.09708832, 6) 9656 elif model == MODEL_NS_R1RHO_2SITE: 9657 if r2eff_estimate == 'direct': 9658 self.assertAlmostEqual(value, 1.56001812, 5) 9659 elif r2eff_estimate == 'MC2000': 9660 self.assertAlmostEqual(value, 1.55833321, 5) 9661 elif r2eff_estimate == 'chi2_pyt': 9662 self.assertAlmostEqual(value, 1.36406712, 5) 9663 9664 elif param == 'kex': 9665 if model == MODEL_DPL94: 9666 if r2eff_estimate == 'direct': 9667 self.assertAlmostEqual(value/1e5, 4460.43711569/1e5, 7) 9668 elif r2eff_estimate == 'MC2000': 9669 self.assertAlmostEqual(value/1e5, 4419.03917195/1e5, 7) 9670 elif r2eff_estimate == 'chi2_pyt': 9671 self.assertAlmostEqual(value/1e5, 6790.22736344/1e5, 7) 9672 elif model == MODEL_TP02: 9673 if r2eff_estimate == 'direct': 9674 self.assertAlmostEqual(value/1e5, 4921.28602757/1e5, 7) 9675 elif r2eff_estimate == 'MC2000': 9676 self.assertAlmostEqual(value/1e5, 4904.70144883/1e5, 7) 9677 elif r2eff_estimate == 'chi2_pyt': 9678 self.assertAlmostEqual(value/1e5, 5146.20306591/1e5, 7) 9679 elif model == MODEL_TAP03: 9680 if r2eff_estimate == 'direct': 9681 self.assertAlmostEqual(value/1e5, 4926.42963491/1e5, 7) 9682 elif r2eff_estimate == 'MC2000': 9683 self.assertAlmostEqual(value/1e5, 4909.86877150/1e5, 7) 9684 elif r2eff_estimate == 'chi2_pyt': 9685 self.assertAlmostEqual(value/1e5, 5152.51105814/1e5, 7) 9686 elif model == MODEL_MP05: 9687 if r2eff_estimate == 'direct': 9688 self.assertAlmostEqual(value/1e5, 4926.44236315/1e5, 7) 9689 elif r2eff_estimate == 'MC2000': 9690 self.assertAlmostEqual(value/1e5, 4909.88110195/1e5, 7) 9691 elif r2eff_estimate == 'chi2_pyt': 9692 self.assertAlmostEqual(value/1e5, 5152.52097111/1e5, 7) 9693 elif model == MODEL_NS_R1RHO_2SITE: 9694 if r2eff_estimate == 'direct': 9695 self.assertAlmostEqual(value/1e5, 5628.66061488/1e5, 6) 9696 elif r2eff_estimate == 'MC2000': 9697 self.assertAlmostEqual(value/1e5, 5610.20221435/1e5, 6) 9698 elif r2eff_estimate == 'chi2_pyt': 9699 self.assertAlmostEqual(value/1e5, 5643.34067090/1e5, 6) 9700 9701 elif param == 'chi2': 9702 if model == MODEL_NOREX: 9703 if r2eff_estimate == 'direct': 9704 self.assertAlmostEqual(value, 848.42016907, 5) 9705 elif r2eff_estimate == 'MC2000': 9706 self.assertAlmostEqual(value, 3363.95829122, 5) 9707 elif r2eff_estimate == 'chi2_pyt': 9708 self.assertAlmostEqual(value, 5976.49946726, 5) 9709 elif model == MODEL_DPL94: 9710 if r2eff_estimate == 'direct': 9711 self.assertAlmostEqual(value, 179.47041241) 9712 elif r2eff_estimate == 'MC2000': 9713 self.assertAlmostEqual(value, 710.24767560) 9714 elif r2eff_estimate == 'chi2_pyt': 9715 self.assertAlmostEqual(value, 612.72616697, 5) 9716 elif model == MODEL_TP02: 9717 if r2eff_estimate == 'direct': 9718 self.assertAlmostEqual(value, 29.33882530, 6) 9719 elif r2eff_estimate == 'MC2000': 9720 self.assertAlmostEqual(value, 114.47142772, 6) 9721 elif r2eff_estimate == 'chi2_pyt': 9722 self.assertAlmostEqual(value, 250.50838162, 5) 9723 elif model == MODEL_TAP03: 9724 if r2eff_estimate == 'direct': 9725 self.assertAlmostEqual(value, 29.29050673, 6) 9726 elif r2eff_estimate == 'MC2000': 9727 self.assertAlmostEqual(value, 114.27987534) 9728 elif r2eff_estimate == 'chi2_pyt': 9729 self.assertAlmostEqual(value, 250.04050719, 5) 9730 elif model == MODEL_MP05: 9731 if r2eff_estimate == 'direct': 9732 self.assertAlmostEqual(value, 29.29054301, 6) 9733 elif r2eff_estimate == 'MC2000': 9734 self.assertAlmostEqual(value, 114.28002272) 9735 elif r2eff_estimate == 'chi2_pyt': 9736 self.assertAlmostEqual(value, 250.04077478, 5) 9737 elif model == MODEL_NS_R1RHO_2SITE: 9738 if r2eff_estimate == 'direct': 9739 self.assertAlmostEqual(value, 34.44010543, 6) 9740 elif r2eff_estimate == 'MC2000': 9741 self.assertAlmostEqual(value, 134.14368365) 9742 elif r2eff_estimate == 'chi2_pyt': 9743 self.assertAlmostEqual(value, 278.55121388, 5) 9744 9745 9746 # Print the final pipe. 9747 model = 'final' 9748 self.interpreter.pipe.switch(pipe_name='%s - relax_disp' % (model)) 9749 print("\nFinal pipe") 9750 9751 # Loop over the spins. 9752 for cur_spin, mol_name, resi, resn, spin_id in spin_loop(full_info=True, return_id=True, skip_desel=True): 9753 # Generate spin string. 9754 spin_string = generate_spin_string(spin=cur_spin, mol_name=mol_name, res_num=resi, res_name=resn) 9755 9756 # Loop over the parameters. 9757 print("Optimised model for spin: %s" % (spin_string)) 9758 param = 'model' 9759 9760 # Get the value. 9761 value = getattr(cur_spin, param) 9762 print("%-10s %-6s %-6s %6s" % ("Parameter:", param, "Value:", value)) 9763 9764 9765 ### Now check some of the written out files. 9766 file_names = ['r1rho_prime', 'r1'] 9767 9768 for file_name_i in file_names: 9769 9770 # Make the file name. 9771 file_name = "%s.out" % file_name_i 9772 9773 # Get the file path. 9774 file_path = get_file_path(file_name, result_dir_name + sep + model) 9775 9776 # Test the file exists. 9777 print("Testing file access to: %s"%file_path) 9778 self.assert_(access(file_path, F_OK)) 9779 9780 # Now open, and compare content, line by line. 9781 file_prod = open(file_path) 9782 lines_prod = file_prod.readlines() 9783 file_prod.close() 9784 9785 # Loop over the lines. 9786 for i, line in enumerate(lines_prod): 9787 # Make the string test 9788 line_split = line.split() 9789 9790 # Continue for comment lines. 9791 if line_split[0] == "#": 9792 print(line), 9793 continue 9794 9795 # Assign the split of the line. 9796 mol_name, res_num, res_name, spin_num, spin_name, val, sd_error = line_split 9797 print(mol_name, res_num, res_name, spin_num, spin_name, val, sd_error) 9798 9799 if res_num == '52': 9800 # Assert that the value is not None. 9801 self.assertNotEqual(val, 'None')
9802